Fix extract css plugin

This commit is contained in:
SleepWalker 2019-12-30 10:23:22 +02:00
parent 4d8704f17c
commit f900321a12

View File

@ -230,13 +230,25 @@ if (isAnalyze) {
} }
if (isProduction) { if (isProduction) {
let cssExtractApplied = false;
webpackConfig.module.rules.forEach(rule => { 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` // replace `style-loader` with `MiniCssExtractPlugin`
rule.use[0] = MiniCssExtractPlugin.loader; 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( webpackConfig.plugins.push(
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: '[name].css?[hash]', filename: '[name].css?[hash]',
@ -275,9 +287,7 @@ if (isProduction) {
manifest: require('./dll/vendor.json'), manifest: require('./dll/vendor.json'),
}), }),
); );
}
if (!isProduction) {
webpackConfig.devServer = { webpackConfig.devServer = {
host: 'localhost', host: 'localhost',
port: 8080, port: 8080,