require('autoprefixer')({
browsers:['last 2 version','>1%','ios 7']
})
开发时需要依赖于各种工具来自动化处理样式表,其中 Autoprefixer 是一个常用的工具,它可以根据项目需求自动添加浏览器前缀,确保样式在不同浏览器中得到正确渲染。
然而,有时在打包或运行时,可能会遇到以下错误:
Replace Autoprefixer browsers option to Browserslist config.
Use browserslist key in package.json or .browserslistrc file.
Using browsers option can cause errors. Browserslist config
can be used for Babel, Autoprefixer, postcss-normalize and other tools.
If you really need to use option, rename it to overrideBrowserslist.
Learn more at:
https://github.com/browserslist/browserslist#readme
https://twitter.com/browserslist
解决方法:
这个错误提示表明我们需要将 Autoprefixer 的配置中的 browsers 选项替换为 Browserslist 配置。下面是解决这个问题的方法:
require('autoprefixer')({
overrideBrowserslist:['last 2 version','>1%','ios 7']
})