vite.config.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import { defineConfig } from 'vite'
  2. import uni from '@dcloudio/vite-plugin-uni'
  3. import tailwindcss from 'tailwindcss'
  4. import autoprefixer from 'autoprefixer'
  5. import postcssRemToResponsivePixel from 'postcss-rem-to-responsive-pixel'
  6. import postcssWeappTailwindcssRename from 'weapp-tailwindcss-webpack-plugin/postcss'
  7. import vwt from 'weapp-tailwindcss-webpack-plugin/vite'
  8. const isH5 = process.env.UNI_PLATFORM === 'h5'
  9. const isApp = process.env.UNI_PLATFORM === 'app'
  10. const weappTailwindcssDisabled = isH5 || isApp
  11. const postcssPlugin = [autoprefixer(), tailwindcss()]
  12. if (!weappTailwindcssDisabled) {
  13. postcssPlugin.push(
  14. postcssRemToResponsivePixel({
  15. rootValue: 32,
  16. propList: ['*'],
  17. transformUnit: 'rpx'
  18. })
  19. )
  20. postcssPlugin.push(postcssWeappTailwindcssRename())
  21. }
  22. // https://vitejs.dev/config/
  23. export default defineConfig({
  24. plugins: [uni(), weappTailwindcssDisabled ? undefined : vwt()],
  25. css: {
  26. postcss: {
  27. plugins: postcssPlugin
  28. }
  29. }
  30. })