From f900321a129d96c3eabf566f130577c8dbe9719d Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Mon, 30 Dec 2019 10:23:22 +0200 Subject: [PATCH] Fix extract css plugin --- webpack.config.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 49d9a5b..3616019 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -230,13 +230,25 @@ if (isAnalyze) { } if (isProduction) { + let cssExtractApplied = false; + webpackConfig.module.rules.forEach(rule => { - if (rule.use && rule.use[0] === 'style-loader') { + if ( + rule.use && + (rule.use[0] === 'style-loader' || rule.use[0].loader === 'style-loader') + ) { // replace `style-loader` with `MiniCssExtractPlugin` rule.use[0] = MiniCssExtractPlugin.loader; + cssExtractApplied = true; } }); + if (!cssExtractApplied) { + throw new Error( + 'Can not locate style-loader to replace it with mini-css-extract-plugin loader', + ); + } + webpackConfig.plugins.push( new MiniCssExtractPlugin({ filename: '[name].css?[hash]', @@ -275,9 +287,7 @@ if (isProduction) { manifest: require('./dll/vendor.json'), }), ); -} -if (!isProduction) { webpackConfig.devServer = { host: 'localhost', port: 8080,