3***@qq.com
3***@qq.com
  • 发布:2024-11-11 09:22
  • 更新:2024-11-11 09:22
  • 阅读:38

postcss-px-to-viewport转换失败

分类:uni-app

我的postcss配置如下,但是没能将项目中的px转换成rpx

// postcss.config.js  

const path = require('path')  
module.exports = {  
  parser: 'postcss-comment',  
  plugins: {  
    'postcss-import': {  
      resolve(id, basedir, importOptions) {  
        if (id.startsWith('~@/')) {  
          return path.resolve(process.env.UNI_INPUT_DIR, id.substr(3))  
        } else if (id.startsWith('@/')) {  
          return path.resolve(process.env.UNI_INPUT_DIR, id.substr(2))  
        } else if (id.startsWith('/') && !id.startsWith('//')) {  
          return path.resolve(process.env.UNI_INPUT_DIR, id.substr(1))  
        }  
        return id  
      }  
    },  
    'autoprefixer': {  
      overrideBrowserslist: ["Android >= 4", "ios >= 8"],  
      remove: process.env.UNI_PLATFORM !== 'h5'  
    },  
    // 借助postcss-px-to-viewport插件,实现rpx转px,文档:https://github.com/evrone/postcss-px-to-viewport/blob/master/README_CN.md  
    // 以下配置,可以将rpx转换为1/2的px,如20rpx=10px,如果要调整比例,可以调整 viewportWidth 来实现  
    'postcss-px-to-viewport': {  
      unitToConvert: 'px',  
      viewportWidth: 375,  
      unitPrecision: 5,  
      propList: ['*'],  
      viewportUnit: 'rpx',  
      fontViewportUnit: 'rpx',  
      selectorBlackList: [],  
      minPixelValue: 1,  
      mediaQuery: false,  
      replace: true,  
      exclude: undefined,  
      include: undefined,  
      landscape: false,  
      landscapeUnit: 'rpx',  
      landscapeWidth: 568  
    },  
    '@dcloudio/vue-cli-plugin-uni/packages/postcss': {}  
  }  
}
2024-11-11 09:22 负责人:无 分享
已邀请:

要回复问题请先登录注册