在项目中使用postcss-plugin-px2rem

2019-01-16  本文已影响0人  afeng_1234
//utils/rem.js
(function () {
  document.body.style.fontSize = '14px'
  const setRem = () => {
    let vw = document.documentElement.clientWidth
    document.documentElement.style.fontSize = vw / 7.5 + 'px'
  }
  setRem()
  window.onresize = setRem
}())

//.postcssrc.js
module.exports = {
  "plugins": {
    "postcss-import": {},
    "postcss-url": {},
    // to edit target browsers: use "browserslist" field in package.json
    "autoprefixer": {},
    "postcss-plugin-px2rem": {
      remUnit: 100,
      mediaQuery: true,
      exclude:"/node_modules/i",
      selectorBlackList: ['html', 'mint-', 'mt-', 'mpvue-', 'calendar', 'iconfont'], //在rem.js全局作用下   排除指定的文件的影响
      propBlackList: ['border']
    }
  }
}
image.png
上一篇下一篇

猜你喜欢

热点阅读