Skip to content

cssnano options not correct pass to cssnano #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zcs19871221 opened this issue Aug 1, 2018 · 7 comments
Closed

cssnano options not correct pass to cssnano #71

zcs19871221 opened this issue Aug 1, 2018 · 7 comments

Comments

@zcs19871221
Copy link

when set in webpack in optimization like this:

new OptimizeCSSAssetsPlugin({ cssProcessorOptions: { calc: false } }),
i found the option not pass,in the cssnano module quickstart.js file, it works this:
const cssnanoOpts = { preset: [ 'default', { calc: false, } ] }; cssnano.process(css, postcssOpts, cssnanoOpts).then(result => { console.log(result.css); });
but in this plugin, use this: return this.options.cssProcessor.process(css.source, processOptions) maybe it is a version problem, but after i change source code it do well.

my cssnano version is 4.0.2, optimize-css-assets-webpack-plugin version is 5.0.0. hope to solve it . thanks.

@kidBrazil
Copy link

I am also having this issue when trying to pass arguments to cssnano. I am trying to get the reduceIndents flag set to false so it will stop mangling my animations.

@blieque
Copy link

blieque commented Aug 10, 2018

I've spend most of today running webpack with the Chrome DevTools to track this down. If you need a quick fix in the meantime:

  1. Open node_modules/optimize-css-assets-webpack-plugin/src/index.js in your project root.
  2. Go to line 62: .cssProcessor.process(css.source, processOptions).
  3. Pass processOptions a second time as a third argument to Plugin.process: .cssProcessor.process(css.source, processOptions, processOptions).

It's not tidy, but it should let you enable Autoprefixer and the other "advanced" cssnano optimisations.

In webpack.prod.config.js:

  optimization: {
    minimizer: [
      new UglifyJsPlugin({ sourceMap: true }),
      new OptimizeCSSAssetsPlugin({
        cssProcessorOptions: {
          map: true,
          preset: ['advanced', {
            autoprefixer: { add: true },
          }],
        },
      }),
    ],
  },

@zcs19871221
Copy link
Author

thanks,i have change the source code. but i have to maintain a fork package,hope it work at next release.

@amatiasq
Copy link

Having this issue too, I was tracking the option object which cssnano didn't receive. Found the same situation.

artkravchenko added a commit to artkravchenko/production-react-boilerplate that referenced this issue Aug 19, 2018
Includes temporary subset of 'optimize-css-assets-webpack-plugin'
via postcss to make chunk scoped optimization possible, that should
be removed when NMFR/optimize-css-assets-webpack-plugin#71
is resolved.
@kingback
Copy link

Same issue, I have tracked the problem at postcss/postcss.es6#L125

creator.process = function (css, processOpts, pluginOpts) {
  return postcss([creator(pluginOpts)]).process(css, processOpts)
}

and optimize-css-assets-webpack-plugin/index.js#L62

this.options.cssProcessor.process(css.source, processOptions)

so the problem is, postcss needs a pluginOpts to config plugin, but optimize-css-assets-webpack-plugin did not apply this option.

@zcs19871221 My temporary hack is rewrite the cssnano.process:

const cssnano = require('cssnano');
const cssnanoProcess = cssnano.process;
cssnano.process = function(source, processOpts, pluginOpts) {
  return cssnanoProcess.call(this, source, processOpts, Object.assign(pluginOpts || {}, {
    preset: [ 'default', { calc: false }
  }));
}

@blieque
Copy link

blieque commented Aug 28, 2018

Yes, it seems like optimize-css-assets-webpack-plugin follows this PostCSS documentation, but the process() function it's using is in fact the one briefly documented here. My uneducated guess is that the process() function expects two options objects covering different subjects, whereas the plugin is passing a single object that contains both those objects' required properties.

@NMFR
Copy link
Owner

NMFR commented Aug 29, 2018

#73 solved this.

If not tell me so i can reopen the issue.

@NMFR NMFR closed this as completed Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants