vue-cli3.0 移动端px转rem以及vue-cli3.0搭建等

网上说的较多的是postcss-pxtorem和postcss-px2rem(postcss-pxtorem配置项介绍https://segmentfault.com/a/11...
这里我采用了postcss-pxtorem,我是用的yarn安装,速度仍是比较快的,之前用npm有时候要等好久。
一、安装依赖包css

yarn add lib-flexible --dev
yarn add postcss-pxtorem --dev

二、main.js中引入lib-flexiblevue

import "lib-flexible/flexible.js"

三、配置postcss-pxtoremvue-cli

vue-cli3 项目postcss-pxtorem的配置放在vue.config.js中(新构建的项目可能会找不到,须要手动在项目根目录建立vue.config.js)
module.exports = {
 css: {
     loaderOptions: {
          postcss: {
            plugins: [
                 // 把px单位换算成rem单位
              require("postcss-pxtorem")({
                    rootValue: 75, // 换算的基数(设计图750的根字体为32)
                    selectorBlackList: [".van"],// 要忽略的选择器并保留为px。
                    propList: ["*"], //能够从px更改成rem的属性。
                    minPixelValue: 2 // 设置要替换的最小像素值。
                })
            ]
          }
     }
}

}
四、建立vue.config.jsnpm

在项目根目录下新建vue.config.js文件与package.json同级
请参考https://blog.csdn.net/u014440483/article/details/87267160(我是看这篇文章的)

五、vue-cli3.0环境搭建(找了一篇文章,和我以前看着搭建的差很少,只是我用的是yarn,最后的npm run serve改成yarn serve就行了)
https://blog.csdn.net/qq_4185...json

相关文章
相关标签/搜索