From c3bf7c688961c0b94d3586f3ea037545330fb698 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 21 Oct 2019 16:26:30 -0700 Subject: [PATCH] webpack: Consolidate production and development plugin configuration. Signed-off-by: Anders Kaseorg --- tools/webpack.config.ts | 62 ++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/tools/webpack.config.ts b/tools/webpack.config.ts index 545fbc4f57..bc15d75f39 100644 --- a/tools/webpack.config.ts +++ b/tools/webpack.config.ts @@ -178,6 +178,36 @@ export default (env?: string): webpack.Configuration[] => { }), ], }, + plugins: [ + new BundleTracker({ + filename: production + ? 'webpack-stats-production.json' + : 'var/webpack-stats-dev.json', + }), + ...production + ? [] + : [ + // Better logging from console for hot reload + new webpack.NamedModulesPlugin(), + // script-loader should load sourceURL in dev + new webpack.LoaderOptionsPlugin({debug: true}), + ], + // Extract CSS from files + new MiniCssExtractPlugin({ + filename: production + ? (data) => { + // This is a special case in order to produce + // a static CSS file to be consumed by + // static/html/5xx.html + if (data.chunk.name === 'error-styles') { + return 'error-styles.css'; + } + return '[name].[contenthash].css'; + } + : "[name].css", + chunkFilename: "[chunkhash].css", + }), + ], }; // Expose Global variables for third party libraries to webpack modules @@ -203,39 +233,9 @@ export default (env?: string): webpack.Configuration[] => { ]; config.module.rules.unshift(...getExposeLoaders(exposeOptions)); - if (production) { - config.plugins = [ - new BundleTracker({filename: 'webpack-stats-production.json'}), - // Extract CSS from files - new MiniCssExtractPlugin({ - filename: (data) => { - // This is a special case in order to produce - // a static CSS file to be consumed by - // static/html/5xx.html - if (data.chunk.name === 'error-styles') { - return 'error-styles.css'; - } - return '[name].[contenthash].css'; - }, - chunkFilename: "[chunkhash].css", - }), - ]; - } else { + if (!production) { // Out JS debugging tools config.entry['common'].push('./static/js/debug.js'); // eslint-disable-line dot-notation - - config.plugins = [ - new BundleTracker({filename: 'var/webpack-stats-dev.json'}), - // Better logging from console for hot reload - new webpack.NamedModulesPlugin(), - // script-loader should load sourceURL in dev - new webpack.LoaderOptionsPlugin({debug: true}), - // Extract CSS from files - new MiniCssExtractPlugin({ - filename: "[name].css", - chunkFilename: "[chunkhash].css", - }), - ]; config.devServer = { clientLogLevel: "error", stats: "errors-only",