From 19a7be47f0986868a1927010e21496e721edaf94 Mon Sep 17 00:00:00 2001 From: Caleb Eby Date: Fri, 27 Aug 2021 10:14:56 -0700 Subject: [PATCH 1/2] Compress away all unused tokens in ESM bundle --- .changeset/tasty-bugs-talk.md | 5 +++++ gulpfile.js/tasks/build-scripts.js | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .changeset/tasty-bugs-talk.md 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..26632fcc3 100644 --- a/gulpfile.js/tasks/build-scripts.js +++ b/gulpfile.js/tasks/build-scripts.js @@ -40,6 +40,12 @@ const createVirtualRootEntry = async () => { .join('\n'); }; +/** @type {import('terser').MinifyOptions} */ +const terserESMOpts = { + compress: { passes: 6 }, + 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 +66,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, From 82152161f98b42cc4f8de1f32c87b25fcbf8ca84 Mon Sep 17 00:00:00 2001 From: Caleb Eby Date: Fri, 27 Aug 2021 10:32:30 -0700 Subject: [PATCH 2/2] Make the output a little more readable --- gulpfile.js/tasks/build-scripts.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gulpfile.js/tasks/build-scripts.js b/gulpfile.js/tasks/build-scripts.js index 26632fcc3..b3f985a79 100644 --- a/gulpfile.js/tasks/build-scripts.js +++ b/gulpfile.js/tasks/build-scripts.js @@ -42,7 +42,8 @@ const createVirtualRootEntry = async () => { /** @type {import('terser').MinifyOptions} */ const terserESMOpts = { - compress: { passes: 6 }, + compress: { passes: 6, join_vars: false, sequences: false }, + module: true, mangle: false, };