我把rem.js放在了assets目錄下,編譯之后報:Uncaught SyntaxError: Unexpected token <這個該怎么解決?
2 回答

holdtom
TA貢獻1805條經驗 獲得超10個贊
rem
都已經工程化了。。。建議不要不要這么手動寫 。
a. 安裝這倆"amfe-flexible": "^2.2.1"
"postcss-pxtorem": "^4.0.1"
b. postcss.config.js
配置(這是我的例子,使用的是vant
。實際規則跟你自己使用的UI庫來決定是否轉換 以及轉換基準)
const autoprefixer = require('autoprefixer');const pxtorem = require('postcss-pxtorem');module.exports = ({ file }) => { let ROOTValue; if (file && file.dirname && (file.dirname.indexOf('vant') > -1) || file.dirname.indexOf('mpvue-calendar') > -1) { ROOTValue = 37.5 } else { ROOTValue = 75 } return { plugins: [ autoprefixer(), pxtorem({ rootValue: ROOTValue, propList: ['*'] }) ] } }
c. main.js
import 'amfe-flexible';
d. 頁面里按照設計圖上的多少px
就直接寫px
,打包后自動轉成rem
添加回答
舉報
0/150
提交
取消