时间: 2021-04-18|39次围观|0 条评论

  • 下载 postcss-pxtorem

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
        }
    }
}

这里只实现了 pxrem,还要安装 amfe-flexible

npm i amfe-flexible -D

main.ts文件中 import 一下就好可以了

import ‘amfe-flexible/index.js’

:可能会出现下面情况
[vite] Internal server error: Loading PostCSS Plugin failed: Cannot find module 'autoprefixer'
vue3.0+vite 使用 postcss-pxtorem 实现移动自适应(px转rem)插图
这时候尝试安装 autoprefixer就可以了

npm i autoprefixer

原文链接:https://blog.csdn.net/weixin_42164539/article/details/113999807

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《vue3.0+vite 使用 postcss-pxtorem 实现移动自适应(px转rem)
   

还没有人抢沙发呢~