Webpack the processing of prefixes in CSS compression

Source: Internet
Author: User
Tags postcss

In the project created by VUE-CLI, after packaging the project with the default Webpack configuration, you find that the prefix for the style in the CSS file is missing, for example: Flex, which should have a prefix attribute but not (Display:-webkit-flex; &&-webkit-flex:1), resulting in a compatibility issue with styles on the iphone 6s Plus.

Postcss CSS prefix is a processing function, in the default configuration of the project, according to the latest two versions of the browser support to add prefixes, and now the browser should be able to support the flex very well, so, do not add a prefix. For this, we can do the following:

// Vue-loader.config.js = { ......  POSTCSS: [    require ('autoprefixer') ({browsers: ['last]Chrome Versions'last5 Firefox versions'Safari >= 6  "ie > 8'})  ]}

After the above processing, the packaged CSS should have the appropriate prefix, but not so, because in the packaging process, CSS has a compression action, in this action, the compression plug-in (with the Optimize-css-assets-webpack-plugin This plugin will once again handle the CSS prefix, removing the code it considers unnecessary, such as unwanted CSS prefixes. Because the prefix of CSS has already been processed with POSTCSS, so the processing of CSS prefixes here is superfluous, we can do the following:

//Webpack.prod.config.js......ConstOptimizecssplugin = require ('Optimize-css-assets-webpack-plugin')......NewOptimizecssplugin ({cssprocessor:require ('Cssnano'), cssprocessoroptions: {discardcomments: {removeall:true },    //Avoid Cssnano recalculation Z-indexSafetrue,    //Cssnano can typically reduce the size of at least 50% by removing annotations, whitespace, repeating rules, outdated browser prefixes, and making other optimizations .//The Cssnano integrates the functionality of the autoprefixer. The autoprefixer is used to clean up unrelated prefixes. Default incompatible iOS8, some webkit prefixes are removed, such as Flex//so choose Close here, use Postcss's Autoprefixer functionAutoprefixer:false}, Canprint:true    //CssProcessorOptions:config.build.productionSourceMap? {safe:true, map: {Inline:false}}: {safe:true}}),......

After packing again, you will find the prefix you want to appear.

Webpack the processing of prefixes in CSS compression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.