diff --git a/.changeset/tasty-bugs-talk.md b/.changeset/tasty-bugs-talk.md new file mode 100644 index 000000000..39113c484 --- /dev/null +++ b/.changeset/tasty-bugs-talk.md @@ -0,0 +1,5 @@ +--- +'@cloudfour/patterns': minor +--- + +Compress away all unused tokens in ESM bundle diff --git a/gulpfile.js/tasks/build-scripts.js b/gulpfile.js/tasks/build-scripts.js index b3c450b40..b3f985a79 100644 --- a/gulpfile.js/tasks/build-scripts.js +++ b/gulpfile.js/tasks/build-scripts.js @@ -40,6 +40,13 @@ const createVirtualRootEntry = async () => { .join('\n'); }; +/** @type {import('terser').MinifyOptions} */ +const terserESMOpts = { + compress: { passes: 6, join_vars: false, sequences: false }, + module: true, + mangle: false, +}; + // The \0 is used to prevent the module name from being a real module name const virtualRootModule = '\0virtual-root-module'; const virtualRootPlugin = () => ({ @@ -60,7 +67,11 @@ const buildJS = async () => { ], }); await Promise.all([ - bundle.write({ format: 'esm', file: path.join(outDir, `${pathName}.mjs`) }), + bundle.write({ + format: 'esm', + file: path.join(outDir, `${pathName}.mjs`), + plugins: terser(terserESMOpts), + }), bundle.write({ format: 'umd', name: globalName,