问题
I use this config for my webpack 2
{
test: /\.css$/i,
use: ExtractTextPlugin.extract({
use: 'css-loader?minimize'
})
}
How to remove all comments based on string mode ? I use this but does not work
'css-loader?minimize&{discardComments:{removeAll:true}}'
Can anyone help me ?
回答1:
You could use optimize-css-assets-webpack-plugin to remove comments: example
回答2:
Might as well keep going and add SASS in there also. Here is our config.
const style_loader = ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{ loader: 'css-loader',
options: {
sourceMap: true
}
},
{ loader: 'postcss-loader',
options: { plugins() { return [Autoprefixer]; } }
},
{ loader: 'resolve-url-loader' },
{ loader: 'sass-loader',
options: { sourceMap: true }
}
]
});
Define that above and then below in your rules you can have:
{
test: /\.scss$/,
use: style_loader
}
Then when you add your plugins:
new ExtractTextPlugin('[name].css'),
I would import one main.scss file into your whatever .js file is your entry point and then import your _partial.scss files into the main.scss file. That way you can break up your styles and start using all of the sass features also.
来源:https://stackoverflow.com/questions/43360631/how-to-remove-all-comments-with-css-loader-with-webpack-2-in-string-mode