postcss.config.js 1.3 KB

123456789101112131415161718192021222324252627282930
  1. const path = require('path');
  2. const judgeComponent = (file) => {
  3. const ignore = ['@nutui', '@varlet'];
  4. return ignore.some((item) => path.join(file).includes(path.join('node_modules', item)));
  5. };
  6. module.exports = {
  7. plugins: {
  8. autoprefixer: { overrideBrowserslist: ['Android 4.1', 'iOS 7.1', 'Chrome > 31', 'ff > 31', 'ie >= 8'] },
  9. 'cnjm-postcss-px-to-viewport': {
  10. unitToConvert: 'px', // 要转化的单位
  11. viewportWidth: 375, // UI设计稿的宽度
  12. unitPrecision: 6, // 转换后的精度,即小数点位数
  13. propList: ['*'], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
  14. viewportUnit: 'vw', // 指定需要转换成的视窗单位,默认vw
  15. fontViewportUnit: 'vw', // 指定字体需要转换成的视窗单位,默认vw
  16. minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
  17. mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
  18. replace: true, // 是否转换后直接更换属性值
  19. include: [],
  20. exclude: [], // 设置忽略文件,用正则做目录名匹配
  21. customFun: ({ file }) => {
  22. // 这个自定义的方法是针对处理vant组件下的设计稿为375问题
  23. const designWidth = judgeComponent(file) ? 375 : 375;
  24. return designWidth;
  25. },
  26. },
  27. },
  28. };