Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tasty-bugs-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudfour/patterns': minor
---

Compress away all unused tokens in ESM bundle
13 changes: 12 additions & 1 deletion gulpfile.js/tasks/build-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => ({
Expand All @@ -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,
Expand Down