css-loader ignores the minimize: false flag.

Created on 11 Sep 2019  路  7Comments  路  Source: webpack-contrib/css-loader

Hey all,

First time creating a Bug Report so sorry if I have missed anything.

  • Operating System: Mac 10.13.6
  • Node Version: v11.10.1
  • NPM Version: v6.7.0
  • webpack Version: v4.38.0
  • css-loader Version: v3.1.0

Expected Behavior

When in production mode and optimization is set to false like so:

optimization: {
    minimize: false
}

CSS should not be minified

Actual Behavior

When in production mode and optimization is set to false like so:

optimization: {
    minimize: false
}

CSS is minified

Code

https://gist.github.com/lukehillonline/90bff2bca8a2f3306408624aa9e6ce55

How Do We Reproduce?

I have created a github repo where you can reproduce the issue:
https://github.com/lukehillonline/css-loader-optimization-test

Once downloaded install all packages.

To test, first, run "start" to see a non minified version, second, run "build" to see a minified version despite the "minimize: false" flag being set.

Most helpful comment

To solve!

The problem is the outputStyle option of sass-loader(node-sass),

I need to adjust the webpack configuration,

...
{
    loader: 'sass-loader',
    options: {
        sourceMap: true,
        sassOptions: {
            // https://github.com/sass/node-sass#outputstyle
            outputStyle: 'expanded'
        }
    }
}
...

All 7 comments

No, you should use plugin for minimize CSS https://github.com/NMFR/optimize-css-assets-webpack-plugin, minimize out of scope loader

Hey @evilebottnawi,

Thanks for coming back, I believe you have misunderstood. I completely agree with you, minimzing CSS should be controlled by a plugin like Optimize CSS Asset Webpack Plugin.

If you look at the case I have produced there is no plugins for CSS minification and minimize: false is set, and still the CSS is minified in production mode.

From my testing I believe that css-loader is performing this minification.

maybe you use old version of css-loader

@evilebottnawi I am using css-loader v3.1.0.

When installing with yarn by using the following command:
yarn add -D css-loader v3.1.0 is the latest installed version.

You can look css-loader code and find we don't use minimizer nowhere, you need investigate who minimize you code

I ran into exactly the same problem.

sass-loader -> postcss-loader -> css-loader -> mini-css-extract-plugin

I don't know which link went wrong.

To solve!

The problem is the outputStyle option of sass-loader(node-sass),

I need to adjust the webpack configuration,

...
{
    loader: 'sass-loader',
    options: {
        sourceMap: true,
        sassOptions: {
            // https://github.com/sass/node-sass#outputstyle
            outputStyle: 'expanded'
        }
    }
}
...
Was this page helpful?
0 / 5 - 0 ratings