HamedFathi
HamedFathi

Reputation: 3969

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

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 ?

Upvotes: 8

Views: 9455

Answers (2)

Kristijan Tomić
Kristijan Tomić

Reputation: 121

You could use optimize-css-assets-webpack-plugin to remove comments: example

Upvotes: 3

jaruesink
jaruesink

Reputation: 1203

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.

Upvotes: -2

Related Questions