From a094abf4da81e58eefc6b73c9be3a8710f9ec4be Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 18 Aug 2020 11:47:20 +0200 Subject: [PATCH] remove comments in js bundles, saves ~100kb --- package.json | 1 + scripts/build.mjs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a82ab0e3..ea98e947 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "postcss-url": "^8.0.0", "regenerator-runtime": "^0.13.7", "rollup": "^1.15.6", + "rollup-plugin-cleanup": "^3.1.1", "serve-static": "^1.13.2", "xxhash": "^0.3.0" } diff --git a/scripts/build.mjs b/scripts/build.mjs index 507aa967..3ae55cad 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -34,6 +34,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; // multi-entry plugin so we can add polyfill file to main import multi from '@rollup/plugin-multi-entry'; +import removeJsComments from 'rollup-plugin-cleanup'; // replace urls of asset names with content hashed version import postcssUrl from "postcss-url"; @@ -173,7 +174,10 @@ async function buildHtml(doc, version, assetPaths, manifestPath) { async function buildJs() { // create js bundle - const bundle = await rollup.rollup({input: 'src/main.js'}); + const bundle = await rollup.rollup({ + input: 'src/main.js', + plugins: [removeJsComments({comments: "none"})] + }); const {output} = await bundle.generate({ format: 'es', name: `${PROJECT_ID}Bundle` @@ -203,7 +207,7 @@ async function buildJsLegacy() { // create js bundle const rollupConfig = { input: ['src/legacy-polyfill.js', 'src/main.js'], - plugins: [multi(), commonjs(), nodeResolve(), babelPlugin] + plugins: [multi(), commonjs(), nodeResolve(), babelPlugin, removeJsComments({comments: "none"})] }; const bundle = await rollup.rollup(rollupConfig); const {output} = await bundle.generate({