diff --git a/package.json b/package.json index 43c87036..ee659f12 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": true, "scripts": { "start": "rollup -c --watch", - "build": "rollup -c", + "build": "rollup -c --environment BUILD:production", "test": "npm run test:lint && npm run test:unit && npm run check-built-assets", "test:lint": "npm run test:lint:styles && npm run test:lint:js && npm run test:lint:i18n", "test:lint:js": "eslint --cache .", diff --git a/rollup.config.js b/rollup.config.js index 5ba5fa4f..a22e6fc5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -5,6 +5,8 @@ const copy = require( 'rollup-plugin-copy' ); const babel = require( '@rollup/plugin-babel' ); const terser = require( '@rollup/plugin-terser' ); +const isProduction = process.env.BUILD === 'production'; + /** * Mapping of import paths to ResourceLoader module names. * See usage in 'plugins' below for explanation. @@ -68,6 +70,12 @@ module.exports = [ `require("${ alias }")`, `require("${ importAliases[ alias ] }")` ); + // Yuck, need to do the same with single apostrophes + // in the event terser is disabled such as during dev builds. + contents = contents.toString().replace( + `require('${ alias }')`, + `require('${ importAliases[ alias ] }')` + ); } ); return contents; } @@ -75,9 +83,9 @@ module.exports = [ hook: 'writeBundle' } ), - babel( { babelHelpers: 'bundled' } ), + isProduction ? babel( { babelHelpers: 'bundled' } ) : null, - terser() + isProduction ? terser() : null ], onwarn: ( warning, warn ) => {