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) {
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,