From e36639f90494d6e82968c99a83ccc2a835e45515 Mon Sep 17 00:00:00 2001 From: "Andrew C. Dvorak" Date: Thu, 17 Aug 2017 14:33:42 -0700 Subject: [PATCH] perf(infrastructure): Cut build time in half with opt-in env var (#1128) A new `GENERATE_SOURCE_MAPS=false` env var disables source map generation in dev mode, which cuts build and recompile times in half. Invoked like so: ```bash GENERATE_SOURCE_MAPS=false npm run dev ``` --- webpack.config.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 8702f1272a3..54e27ada0db 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -26,6 +26,10 @@ const OUT_PATH = path.resolve('./build'); const PUBLIC_PATH = '/assets/'; const IS_DEV = process.env.MDC_ENV === 'development'; const IS_PROD = process.env.MDC_ENV === 'production'; +const GENERATE_SOURCE_MAPS = + process.env.MDC_GENERATE_SOURCE_MAPS === 'true' || + (process.env.MDC_GENERATE_SOURCE_MAPS !== 'false' && IS_DEV); +const DEVTOOL = GENERATE_SOURCE_MAPS ? 'source-map' : false; const banner = [ '/*!', @@ -50,20 +54,20 @@ const CSS_LOADER_CONFIG = [ { loader: 'css-loader', options: { - sourceMap: true, + sourceMap: GENERATE_SOURCE_MAPS, }, }, { loader: 'postcss-loader', options: { - sourceMap: IS_DEV, - plugins: () =>[require('autoprefixer')({grid: false})], + sourceMap: GENERATE_SOURCE_MAPS, + plugins: () => [require('autoprefixer')({grid: false})], }, }, { loader: 'sass-loader', options: { - sourceMap: true, + sourceMap: GENERATE_SOURCE_MAPS, includePaths: glob.sync('packages/*/node_modules').map((d) => path.join(__dirname, d)), }, }, @@ -106,7 +110,7 @@ module.exports = [{ devServer: { disableHostCheck: true, }, - devtool: IS_DEV ? 'source-map' : false, + devtool: DEVTOOL, module: { rules: [{ test: /\.js$/, @@ -133,7 +137,7 @@ module.exports = [{ devServer: { disableHostCheck: true, }, - devtool: IS_DEV ? 'source-map' : false, + devtool: DEVTOOL, module: { rules: [{ test: /\.js$/, @@ -190,7 +194,7 @@ module.exports = [{ devServer: { disableHostCheck: true, }, - devtool: IS_DEV ? 'source-map' : false, + devtool: DEVTOOL, module: { rules: [{ test: /\.scss$/, @@ -220,7 +224,7 @@ if (IS_DEV) { devServer: { disableHostCheck: true, }, - devtool: 'source-map', + devtool: DEVTOOL, module: { rules: [{ test: /\.scss$/,