下載 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
}
}
}
這里只實現了 px轉rem,還要安裝 amfe-flexible
npm i amfe-flexible autoprefixer -D
在main.ts文件中 import 一下就好可以了
import ‘amfe-flexible/index.js’
