Skip to content

Commit 70caf04

Browse files
committed
Don't publish empty modules
The ES modules build (which is only used by embroider, not classic builds) includes several empty modules. They're type-only, and result in empty files after transpiling typescript. This isn't necessarily wrong but it's unnecessary and it can trigger bugs in systems that are trying to use the presence of import/export to detect ESM format.
1 parent e88cf93 commit 70caf04

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

rollup.config.mjs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function esmConfig() {
5858
resolveTS(),
5959
version(),
6060
resolvePackages(exposedDependencies(), hiddenDependencies()),
61+
pruneEmptyBundles(),
6162
],
6263
};
6364
}
@@ -443,7 +444,7 @@ function templateCompilerConfig() {
443444
});
444445
config.output.globals = (id) => {
445446
return `(() => {
446-
try {
447+
try {
447448
return require('${id}');
448449
} catch (err) {
449450
return ${externals[id]}
@@ -452,3 +453,16 @@ function templateCompilerConfig() {
452453
};
453454
return config;
454455
}
456+
457+
function pruneEmptyBundles() {
458+
return {
459+
name: 'prune-empty-bundles',
460+
generateBundle(options, bundles) {
461+
for (let [key, bundle] of Object.entries(bundles)) {
462+
if (bundle.code.trim() === '') {
463+
delete bundles[key];
464+
}
465+
}
466+
},
467+
};
468+
}

0 commit comments

Comments
 (0)