Skip to content

Commit 5784d46

Browse files
authored
Compress away all unused tokens in ESM bundle (#1507)
1 parent f14ccb0 commit 5784d46

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

.changeset/tasty-bugs-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': minor
3+
---
4+
5+
Compress away all unused tokens in ESM bundle

gulpfile.js/tasks/build-scripts.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ const createVirtualRootEntry = async () => {
4040
.join('\n');
4141
};
4242

43+
/** @type {import('terser').MinifyOptions} */
44+
const terserESMOpts = {
45+
compress: { passes: 6, join_vars: false, sequences: false },
46+
module: true,
47+
mangle: false,
48+
};
49+
4350
// The \0 is used to prevent the module name from being a real module name
4451
const virtualRootModule = '\0virtual-root-module';
4552
const virtualRootPlugin = () => ({
@@ -60,7 +67,11 @@ const buildJS = async () => {
6067
],
6168
});
6269
await Promise.all([
63-
bundle.write({ format: 'esm', file: path.join(outDir, `${pathName}.mjs`) }),
70+
bundle.write({
71+
format: 'esm',
72+
file: path.join(outDir, `${pathName}.mjs`),
73+
plugins: terser(terserESMOpts),
74+
}),
6475
bundle.write({
6576
format: 'umd',
6677
name: globalName,

0 commit comments

Comments
 (0)