Skip to content
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

It remove browser prefix by default, but I want to save prefix when generate css files. #51

Closed
ansenhuang opened this issue May 19, 2018 · 6 comments

Comments

@ansenhuang
Copy link

No description provided.

@ansenhuang
Copy link
Author

So what can I do ?

@zhangolve
Copy link

me too.

@NMFR
Copy link
Owner

NMFR commented May 23, 2018

By default the CSS manipulation that this plugin does is delegated to cssnano. You can control the cssnano config in the cssProcessorOptions option.

This is a cssnano related issue.

@NMFR NMFR closed this as completed May 23, 2018
@ansenhuang
Copy link
Author

I finded the solution, we can pass by some option to cssnano, please view following example:

new OptimizeCssAssetsPlugin({
    assetNameRegExp: /\.css$/g,
    cssProcessorOptions: {
      safe: true,
      autoprefixer: { disable: true },
      mergeLonghand: false,
      discardComments: {
        removeAll: true
      }
    },
    canPrint: true
  });

the option of autoprefixer: { disable: true } will disable cssnano's autoprefixer and saved prefixer that already exist by ourselves.

@malcolm-kee
Copy link

I able to make it work, sharing here just in case anyone stumble upon same issue.

It seems like if you set browserslist key in your package.json, then the optimization will remove the prefix only if the prefix is not required based on your browserlist. Autoprefixer has a section that explains this in its docs.

Example of browserslist:

{
"browserslist": [
    ">1%",
    "last 4 versions",
    "not ie < 9"
  ]
}

@blue-lightning
Copy link

While ansenhuang's answer is correct, if you want to only disable Autoprefixer's remove outdated prefixes function and keep everything else, replace disable: true with remove: false.

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

5 participants