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’
:可能會出現下面情況
[vite] Internal server error: Loading PostCSS Plugin failed: Cannot find module 'autoprefixer'
這時候嘗試安裝
autoprefixer
就可以了
npm i autoprefixer