vite.config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import path from 'path'
  4. import AutoImport from 'unplugin-auto-import/vite'
  5. import Components from 'unplugin-vue-components/vite'
  6. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  7. import postcsspxtoviewport from 'postcss-px-to-viewport'
  8. // https://vite.dev/config/
  9. export default defineConfig({
  10. server: {
  11. open: true,
  12. prot: 8088
  13. },
  14. resolve: {
  15. // https://cn.vitejs.dev/config/#resolve-alias
  16. alias: {
  17. // 设置路径
  18. '~': path.resolve(__dirname, './'),
  19. // 设置别名
  20. '@': path.resolve(__dirname, './src')
  21. }
  22. // https://cn.vitejs.dev/config/#resolve-extensions
  23. // extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  24. },
  25. optimizeDeps: {
  26. // 开发时 解决这些commonjs包转成esm包
  27. include: [
  28. '@jiaminghi/c-render',
  29. '@jiaminghi/c-render/lib/plugin/util',
  30. '@jiaminghi/charts/lib/util/index',
  31. '@jiaminghi/charts/lib/util',
  32. '@jiaminghi/charts/lib/extend/index',
  33. '@jiaminghi/charts',
  34. '@jiaminghi/color'
  35. ]
  36. },
  37. plugins: [
  38. vue(),
  39. AutoImport({
  40. resolvers: [ElementPlusResolver()]
  41. }),
  42. Components({
  43. resolvers: [ElementPlusResolver()]
  44. })
  45. ],
  46. css: {
  47. postcss: {
  48. plugins: [
  49. postcsspxtoviewport({
  50. unitToConvert: 'px', // 要转化的单位
  51. // viewportHeight: 1087, // 可选,视口高度,通常不需要设置
  52. viewportWidth: 3840, // UI设计稿的宽度
  53. unitPrecision: 4, // 转换后的精度,即小数点位数
  54. propList: ['*'], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
  55. // viewportUnit: 'vh', // 指定需要转换成的视窗单位,默认vw
  56. // fontViewportUnit: 'vh', // 指定字体需要转换成的视窗单位,默认vw
  57. viewportUnit: 'vw', // 指定需要转换成的视窗单位,默认vw
  58. fontViewportUnit: 'vw', // 指定字体需要转换成的视窗单位,默认vw
  59. selectorBlackList: [], // 指定不转换为视窗单位的类名,
  60. minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
  61. mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
  62. replace: true, // 是否转换后直接更换属性值
  63. exclude: [/node_modules\/(?!element-plus)/], // 设置忽略文件,用正则做目录名匹配
  64. landscape: false // 是否处理横屏情况
  65. })
  66. ]
  67. }
  68. },
  69. })