postcss-px-to-viewport

我用的1.1.1版本

首先在webpack里面配置,找不到webpack.config.js就先暴露出来npm run eject

找到webpcak对应地点进行配置

options: {
          postcssOptions: {
            // Necessary for external CSS imports to work
            // https://github.com/facebook/create-react-app/issues/2677
            ident: "postcss",
            config: false,
            plugins: !useTailwind
              ? [
                  "postcss-flexbugs-fixes",
                  [
                    "postcss-preset-env",
                    {
                      autoprefixer: {
                        flexbox: "no-2009",
                      },
                      stage: 3,
                    },
                  ],
                  // Adds PostCSS Normalize as the reset css with default options,
                  // so that it honors browserslist config in package.json
                  // which in turn let's users customize the target behavior as per their needs.
                  [
                    'postcss-px-to-viewport',
                    {
                      viewportWidth: 1920, // (Number) The width of the viewport.
                      viewportHeight: 2925.5, // (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.
                    }
                  ],                  
                  "postcss-normalize",
                ]
              : [
                  "tailwindcss",
                  "postcss-flexbugs-fixes",
                  [
                    "postcss-preset-env",
                    {
                      autoprefixer: {
                        flexbox: "no-2009",
                      },
                      stage: 3,
                    },
                  ],
                ],
          },
          sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
        },

配置完毕npm start就可以看见转化为vw,如果要更改配置,改完之后重新启动项目就可以看见改变

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值