How to remove all comments with CSS Loader with webpack 2 in string mode?

梦想的初衷 提交于 2020-12-08 06:44:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!