vite: 4.1.4
首先去vite官網(wǎng)逛逛,因為autoprefixer屬于postcss類,所以在官網(wǎng)的配置共享配置中找到關于css.postcss配置項
發(fā)現(xiàn)vite對于postcss有兩種不同的配置方式:1.內(nèi)聯(lián)配置 2.開發(fā)者使用postcss-load-config插件推薦的配置方法(vite內(nèi)置了postcss-load-config插件)具體怎么配置可以看插件官網(wǎng)?GitHub - postcss/postcss-load-config: Autoload Config for PostCSSzAutoload Config for PostCSS. Contribute to postcss/postcss-load-config development by creating an account on GitHub.https://github.com/postcss/postcss-load-config
這里我選擇內(nèi)聯(lián)配置(懶得新建一個文件了),?這里要注意對于postcss配置對象里的plugins選項vite只支持數(shù)組格式,大概長這樣:
?
接著下載
npm i autoprefixer -D
然后在vite.config.json里加入
// vite.config.json
export default defineConfig({
// ......
css: {
postcss: {
plugins: [
require('autoprefixer')()
]
}
}
})
這里autoprefixer就采取默認配置了不單獨配置了沒啥用,具體配置去autoprefixer文檔里看
GitHub - postcss/autoprefixer: Parse CSS and add vendor prefixes to rules by Can I Use
最后測試成功自動加了前綴文章來源:http://www.zghlxwxcb.cn/news/detail-469788.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-469788.html
到了這里,關于vite配置postcss-autoprefixer,實現(xiàn)自動添加css屬性前綴的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!