From c25d38784075824ea7db29380c8f76d50df78ea2 Mon Sep 17 00:00:00 2001 From: Neri Marschik Date: Wed, 8 Feb 2017 11:10:36 +0900 Subject: [PATCH] fix(webpack): Fix uglifyjs breaking and disable modules for webpack tree shaking to work Uglify broke because of the include statement I added in hope it would speed up the build. To use tree shaking with webpack babel should not convert modules into es5 code. That broke the testing process. I added a babel environment variable and environment babel rules switch to make both work. --- package.json | 16 ++++++++++++++-- webpack.config.js | 6 +++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 1a784df3157..99b90f59498 100644 --- a/package.json +++ b/package.json @@ -80,11 +80,23 @@ }, "babel": { "presets": [ - "es2015" + [ + "es2015", + { + "modules": false + } + ] ], "plugins": [ "transform-object-assign" - ] + ], + "env": { + "test": { + "presets": [ + "es2015" + ] + } + } }, "config": { "validate-commit-msg": { diff --git a/webpack.config.js b/webpack.config.js index 633ec0ae3f0..4796265992e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -41,6 +41,11 @@ const createBannerPlugin = () => new webpack.BannerPlugin({ entryOnly: true, }); +const LIFECYCLE_EVENT = process.env.npm_lifecycle_event; +if (LIFECYCLE_EVENT == 'test' || LIFECYCLE_EVENT == 'test:watch') { + process.env.BABEL_ENV = 'test'; +} + module.exports = [{ name: 'js-components', entry: { @@ -92,7 +97,6 @@ module.exports = [{ module: { rules: [{ test: /\.js$/, - include: [path.resolve(__dirname, 'packages/material-components-web')], exclude: /node_modules/, loader: 'babel-loader', options: {