vue cli3.0配置rem 跟 vue cli2.0配置rem有着明显的改变在升级后缺少了postcss文件所以在试用rem 配置的时候会有一点改变。
基本步骤不变,基本步骤如下:
1、安装amfe-flexible插件
npm i amfe-flexible -S
2、在main.js里引入
import 'amfe-flexible';
3、然后安装postcss-px2rem插件
npm i postcss-px2rem -S
4、在package.json中配置
"postcss": {
"plugins": {
"autoprefixer": {},
"postcss-px2rem": {
"remUnit": 37.5
}
}
}
插入后文件内容如下(在这里还可以改变相关配置插件的版本,例如导入的vuex、vue-router);同时,想要改变插件版本也可以在page.json中改变,然后 npm i 来改变版本
{
"name": "svue",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"amfe-flexible": "^2.2.1",
"core-js": "^3.6.5",
"postcss-px2rem": "^0.3.0",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuex": "^3.4.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-template-compiler": "^2.6.11"
},
"postcss": {
"plugins": {
"autoprefixer": {},
"postcss-px2rem": {
"remUnit": 37.5
}
}
}
}