Skip to content

Commit ef02da8

Browse files
committed
fix: fix lib crash
1 parent 3555d23 commit ef02da8

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

css-loader-config.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin')
2-
const findUp = require('find-up')
1+
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
2+
const findUp = require('find-up');
3+
const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin');
34

4-
const fileExtensions = new Set()
5-
let extractCssInitialized = false
5+
const fileExtensions = new Set();
6+
let extractCssInitialized = false;
67

78
module.exports = (
89
config,
@@ -18,7 +19,7 @@ module.exports = (
1819
) => {
1920
// We have to keep a list of extensions for the splitchunk config
2021
for (const extension of extensions) {
21-
fileExtensions.add(extension)
22+
fileExtensions.add(extension);
2223
}
2324

2425
if (!isServer && config.optimization.splitChunks.cacheGroups) {
@@ -27,7 +28,7 @@ module.exports = (
2728
test: new RegExp(`\\.+(${[...fileExtensions].join('|')})$`),
2829
chunks: 'all',
2930
enforce: true
30-
}
31+
};
3132
}
3233

3334
if (!isServer && !extractCssInitialized) {
@@ -41,48 +42,53 @@ module.exports = (
4142
chunkFilename: dev
4243
? 'static/chunks/[name].chunk.css'
4344
: 'static/chunks/[name].[contenthash:8].chunk.css',
44-
orderWarning: false,
45-
reloadAll: true
45+
hot: dev
4646
})
47-
)
48-
extractCssInitialized = true
47+
);
48+
extractCssInitialized = true;
4949
}
5050

5151
if (!dev) {
5252
if (!Array.isArray(config.optimization.minimizer)) {
53-
config.optimization.minimizer = []
53+
config.optimization.minimizer = [];
5454
}
55-
const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin');
56-
config.optimization.minimizer.push(new OptimizeCssAssetsWebpackPlugin({}))
55+
config.optimization.minimizer.push(
56+
new OptimizeCssAssetsWebpackPlugin({
57+
cssProcessorOptions: {
58+
discardComments: { removeAll: true }
59+
}
60+
})
61+
);
5762
}
5863

5964
const postcssConfig = findUp.sync('postcss.config.js', {
6065
cwd: config.context
61-
})
62-
let postcssLoader
66+
});
67+
let postcssLoader;
6368

6469
if (postcssConfig) {
6570
// Copy the postcss-loader config options first.
6671
const postcssOptionsConfig = Object.assign(
6772
{},
6873
postcssLoaderOptions.config,
6974
{ path: postcssConfig }
70-
)
75+
);
7176

7277
postcssLoader = {
7378
loader: 'postcss-loader',
7479
options: Object.assign({}, postcssLoaderOptions, {
7580
config: postcssOptionsConfig
7681
})
77-
}
82+
};
7883
}
7984

8085
const cssLoader = {
81-
loader: isServer ? 'css-loader/locals' : 'css-loader',
86+
loader: 'css-loader',
8287
options: Object.assign(
8388
{},
8489
{
8590
modules: cssModules,
91+
exportOnlyLocals: isServer,
8692
localIdentName: dev
8793
? '[name]__[local]--[hash:base64:5]'
8894
: '[hash:base64:5]',
@@ -91,16 +97,16 @@ module.exports = (
9197
},
9298
cssLoaderOptions
9399
)
94-
}
100+
};
95101

96102
// When not using css modules we don't transpile on the server
97103
if (isServer && !cssLoader.options.modules) {
98-
return ['ignore-loader']
104+
return ['ignore-loader'];
99105
}
100106

101107
// When on the server and using css modules we transpile the css
102108
if (isServer && cssLoader.options.modules) {
103-
return [cssLoader, postcssLoader, ...loaders].filter(Boolean)
109+
return [cssLoader, postcssLoader, ...loaders].filter(Boolean);
104110
}
105111

106112
return [
@@ -109,5 +115,5 @@ module.exports = (
109115
cssLoader,
110116
postcssLoader,
111117
...loaders
112-
].filter(Boolean)
113-
}
118+
].filter(Boolean);
119+
};

0 commit comments

Comments
 (0)