Skip to content
Prev Previous commit
Next Next commit
optimize default-export-only bundles
  • Loading branch information
developit committed Jun 5, 2022
commit 9239801b682af9fd15124056136a46220663b933
17 changes: 17 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,23 @@ function createConfig(options, entry, format, writeMeta) {
jsxImportSource: options.jsxImportSource || false,
},
}),

/** @type {import('rollup').Plugin} */
({
name: 'export-default-simplify',
renderChunk(code, chunk, options) {
let out = code.replace(
/([};\n])export\s*\{\s*([a-zA-Z0-9_$]+)\s+as\s+default\s*\};/,
(s, before, name) => {
return `${before}export default ${name};`;
},
);
if (out !== code) {
return { code: out, map: null };
}
},
}),

options.compress !== false && [
terser({
compress: Object.assign(
Expand Down