问题
I use webpack 4 and need to optimize and minify css after build comand. I found optimize-css-assets-webpack-plugin but this plugin doesn't work. Do you use these plugins or loaders for optimizing css or not? Do we need to use it or not?
回答1:
With webpack 4 you need to bring your own. To minify the output, use a plugin like optimize-css-assets-webpack-plugin. However, note that setting optimization.minimizer overrides the defaults provided by webpack, so make sure to also specify a JS minimizer:
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
module.exports = {
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true // set to true if you want JS source maps
}),
new OptimizeCSSAssetsPlugin({})
]
},
plugins: [
],
module: {
rules: [
{
test: /\.css$/,
use: [
"css-loader"
]
}
]
}
}
来源:https://stackoverflow.com/questions/50628268/webpack-css-optimization-and-minify