I was setting the Webpack loaders config for .css
and .scss
files, I noticed that when using --mode production
I'm getting minimized CSS as the final output without even using a minimizer explicitly, here's my loaders config:
{
// Match .css or .scss
test: /\.s?css$/,
use: [
isProd
// In production extract the CSS into separate files
? {
loader: MiniCssExtractPlugin.loader,
options: {
hmr: !isProd
}
}
// In development inject the styles into the DOM
: 'style-loader',
{
loader: 'css-loader'
},
{
loader: 'sass-loader',
options: {
sourceMap: false
}
}
]
}
I'm using sass-loader
with node-sass
and mini-css-extract-plugin
to extract the CSS into separate files, which suggests using optimize-css-assets-webpack-plugin
for minimizing the CSS by overriding optimization.minimizer
, but I'm already getting minimized output without installing this plugin.
To find what's causing this behavior I tried processing CSS files with and without sass-loader
and I found out that sass-loader
might be causing this behavior but it doesn't have any option for minimizing the CSS.
So what's causing this behavior? And do I even still need optimize-css-assets-webpack-plugin
if my CSS files are minimized?