Hi Guys,
I have a problem, When I use cssnano with postcss-loader in Webpack 4 and mini extract CSS plugin the Sourcemap gets minified too. Example:

#### webpack.config.js
module.exports = {
devtool: 'source-map',
entry: {
foo: [
'./base.css',
'./basic.css'
]
},
optimization: {
splitChunks: {
cacheGroups: {
fooStyles: {
name: 'foo',
test: (m,c,entry = 'foo') => m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry,
chunks: 'all',
enforce: true
}
}
}
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
})
],
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false,
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
ident: 'postcss',
plugins: [
require('autoprefixer')({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
],
flexbox: 'no-2009',
}),
require('cssnano')({ preset: 'default' })
]
}
}
],
}
]
}
}
What it is wrong here?
Ok. It turns out that the sourcemap option should be set inside the css-loader also:
{
loader: 'css-loader',
options: {
url: false,
sourceMap: true
}
@aryaroudi don't use cssnano in postcss-loader, use https://github.com/intervolga/optimize-cssnano-plugin, using on postcss-loader makes impossible same optimization, also css-loader can rewrite some css stuff
@aryaroudi don't use
cssnanoinpostcss-loader, use https://github.com/intervolga/optimize-cssnano-plugin, using onpostcss-loadermakes impossible same optimization, alsocss-loadercan rewrite some css stuff
Very Good point. It would be great if you guys update the postcss-loader documentation, many people choose the bad approach.
Thanks
Most helpful comment
Very Good point. It would be great if you guys update the postcss-loader documentation, many people choose the bad approach.
Thanks