vite.config.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import postcsspxtoviewport from 'postcss-px-to-viewport'
  5. // https://vitejs.dev/config/
  6. export default defineConfig({
  7. plugins: [
  8. vue()
  9. ],
  10. resolve: {
  11. alias: {
  12. '@': fileURLToPath(new URL('./src', import.meta.url))
  13. }
  14. },
  15. css: {
  16. preprocessorOptions: {
  17. scss: {
  18. api: "modern-compiler" // or 'modern'
  19. }
  20. },
  21. postcss: {
  22. plugins: [
  23. postcsspxtoviewport({
  24. unitToConvert: "px", // 要转化的单位
  25. viewportWidth: 1080, // UI设计稿的宽度
  26. unitPrecision: 6, // 转换后的精度,即小数点位数
  27. propList: ["*"], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
  28. viewportUnit: "vh", // 指定需要转换成的视窗单位,默认vw
  29. fontViewportUnit: "vh", // 指定字体需要转换成的视窗单位,默认vw
  30. selectorBlackList: [], // 指定不转换为视窗单位的类名,
  31. minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
  32. mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
  33. replace: true, // 是否转换后直接更换属性值
  34. exclude: [/node_modules/], // 设置忽略文件,用正则做目录名匹配
  35. // include: [/overview_4k/],
  36. landscape: false // 是否处理横屏情况
  37. }),
  38. ]
  39. }
  40. },
  41. publicPath: './'
  42. })