postcss.config.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. if (process.env.VITE_ROOT_DIR) { // vite
  2. const {
  3. uniPostcssPlugin,
  4. parseRpx2UnitOnce,
  5. } = require('@dcloudio/uni-cli-shared')
  6. module.exports = {
  7. plugins: [
  8. uniPostcssPlugin(
  9. Object.assign({
  10. page: process.env.UNI_PLATFORM === 'h5' ? 'uni-page-body' : 'body'
  11. },
  12. parseRpx2UnitOnce(process.env.UNI_INPUT_DIR)
  13. )
  14. ),
  15. require('autoprefixer')(),
  16. ],
  17. }
  18. } else {
  19. const path = require('path')
  20. module.exports = {
  21. parser: 'postcss-comment',
  22. plugins: {
  23. 'postcss-import': {
  24. resolve(id, basedir, importOptions) {
  25. if (id.startsWith('~@/')) {
  26. return path.resolve(process.env.UNI_INPUT_DIR, id.substr(3))
  27. } else if (id.startsWith('@/')) {
  28. return path.resolve(process.env.UNI_INPUT_DIR, id.substr(2))
  29. } else if (id.startsWith('/') && !id.startsWith('//')) {
  30. return path.resolve(process.env.UNI_INPUT_DIR, id.substr(1))
  31. }
  32. return id
  33. }
  34. },
  35. 'autoprefixer': {
  36. overrideBrowserslist: ["> 1%", "last 2 versions", "not dead"],
  37. remove: process.env.UNI_PLATFORM !== 'h5',
  38. ignoreUnknownVersions: true
  39. },
  40. '@dcloudio/vue-cli-plugin-uni/packages/postcss': {}
  41. }
  42. }
  43. }