美文网首页
vue3+vite 使用postcss-pxtorem

vue3+vite 使用postcss-pxtorem

作者: PharkiLL | 来源:发表于2022-03-28 10:43 被阅读0次
  • 安装插件
npm i  postcss-pxtorem -D
  • 与package.json同级目录创建postcss.config.js文件
module.exports = {
    plugins: {
        autoprefixer: {
            overrideBrowserslist: [
                "Android 4.1",
                "iOS 7.1",
                "Chrome > 31",
                "ff > 31",
                "ie >= 8",
                "last 10 versions", // 所有主流浏览器最近10版本用
            ],
            grid: true,
        },
        'postcss-pxtorem': {
            rootValue: 37.5,
            propList: ['*'],
            unitPrecision: 5
        }
    }
}
 
  • 这里只实现了 px转rem,还要安装 amfe-flexible
npm i amfe-flexible -D
  • 在main.ts文件中 import 一下就好可以了
import 'amfe-flexible/index.js'
  • 最后安装autoprefixer, 否则编译会报错
npm i autoprefixer

相关文章

网友评论

      本文标题:vue3+vite 使用postcss-pxtorem

      本文链接:https://www.haomeiwen.com/subject/udqpjrtx.html