react使用 postcss-px-to-viewport

2022-02-14  本文已影响0人  豆屁屁

react 项目中css样式px自动转vw,适配移动端和pc端。修改下配置项里面的viewportWidth和viewportHeigh

//1.npm方式:
npm install postcss-loader postcss-px-to-viewport --save-dev

//2.yarn安装:
yarn add -D postcss-loader postcss-px-to-viewport
若报错,有git的可以通过 
    git add .
    git commit -m '暴露项目配置项'
    npm run eject
npm方式:
    npm run eject

cnpm方式:
    cnpm run eject
    
yarn方式:
    yarn eject
[
  'postcss-px-to-viewport',
  {
    
    viewportWidth: 750, // (Number) The width of the viewport.
    viewportHeight: 1334, // (Number) The height of the viewport. -- 一般不需要配置
    unitPrecision: 3, // (Number) The decimal numbers to allow the REM units to grow to.
    viewportUnit: "vw", // (String) Expected units.
    selectorBlackList: [], // (Array) The selectors to ignore and leave as px.
    minPixelValue: 1, // (Number) Set the minimum pixel value to replace.
    mediaQuery: false // (Boolean) Allow px to be converted in media queries.
  }
],
require('postcss-px-to-viewport')({
    
  viewportWidth: 750, // (Number) The width of the viewport.
  viewportHeight: 1334, // (Number) The height of the viewport. -- 一般不需要配置
  unitPrecision: 3, // (Number) The decimal numbers to allow the REM units to grow to.
  viewportUnit: "vw", // (String) Expected units.
  selectorBlackList: [], // (Array) The selectors to ignore and leave as px.
  minPixelValue: 1, // (Number) Set the minimum pixel value to replace.
  mediaQuery: false // (Boolean) Allow px to be converted in media queries.
}),
上一篇 下一篇

猜你喜欢

热点阅读