postcss.config.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const path = require('path')
  2. module.exports = {
  3. parser: 'postcss-comment',
  4. plugins: {
  5. 'postcss-import': {
  6. resolve(id, basedir, importOptions) {
  7. if (id.startsWith('~@/')) {
  8. return path.resolve(process.env.UNI_INPUT_DIR, id.substr(3))
  9. } else if (id.startsWith('@/')) {
  10. return path.resolve(process.env.UNI_INPUT_DIR, id.substr(2))
  11. } else if (id.startsWith('/') && !id.startsWith('//')) {
  12. return path.resolve(process.env.UNI_INPUT_DIR, id.substr(1))
  13. }
  14. return id
  15. }
  16. },
  17. 'autoprefixer': {
  18. overrideBrowserslist: ["Android >= 4", "ios >= 8"],
  19. remove: process.env.UNI_PLATFORM !== 'h5'
  20. },
  21. // 借助postcss-px-to-viewport插件,实现px转rem,文档:https://github.com/evrone/postcss-px-to-viewport/blob/master/README_CN.md
  22. // 以下配置,可以将px转换为rem,如果要调整比例,可以调整 viewportWidth 来实现
  23. 'postcss-px-to-viewport': {
  24. unitToConvert: 'px', // 需要转换的单位。我这里是px,如果你的项目都是用的rpx,就改成rpx
  25. viewportWidth: 1024,// 密度,一般为750 || 375。这里可以自己修改
  26. unitPrecision: 5,
  27. propList: ['*'],
  28. viewportUnit: "vh", // 指定需要转换成的视窗单位,默认vw
  29. fontViewportUnit: 'vh', // 字体需要转成的单位,只针对 font-size 属性
  30. selectorBlackList: [],
  31. minPixelValue: 1,
  32. mediaQuery: false,
  33. replace: true,
  34. exclude: undefined,
  35. include: undefined,
  36. landscape:false,
  37. landscapeUnit: 'vh', // 横屏时使用的单位
  38. landscapeWidth: 1280 // 横屏时使用的视窗宽度
  39. },
  40. '@dcloudio/vue-cli-plugin-uni/packages/postcss': {}
  41. }
  42. }