vite.config.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. "highcharts",
  36. "highcharts/highcharts-3d",
  37. ],
  38. },
  39. plugins: [
  40. vue(),
  41. AutoImport({
  42. resolvers: [ElementPlusResolver()],
  43. }),
  44. Components({
  45. resolvers: [ElementPlusResolver()],
  46. }),
  47. ],
  48. css: {
  49. postcss: {
  50. plugins: [
  51. postcsspxtoviewport({
  52. unitToConvert: "px", // 要转化的单位
  53. // viewportHeight: 1080, // 可选,视口高度,通常不需要设置
  54. viewportWidth: 3840, // UI设计稿的宽度
  55. unitPrecision: 4, // 转换后的精度,即小数点位数
  56. propList: ["*"], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
  57. // viewportUnit: 'vh', // 指定需要转换成的视窗单位,默认vw
  58. // fontViewportUnit: 'vh', // 指定字体需要转换成的视窗单位,默认vw
  59. viewportUnit: "vw", // 指定需要转换成的视窗单位,默认vw
  60. fontViewportUnit: "vw", // 指定字体需要转换成的视窗单位,默认vw
  61. selectorBlackList: [], // 指定不转换为视窗单位的类名,
  62. minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
  63. mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
  64. replace: true, // 是否转换后直接更换属性值
  65. exclude: [/node_modules\/(?!element-plus)/], // 设置忽略文件,用正则做目录名匹配
  66. landscape: false, // 是否处理横屏情况
  67. }),
  68. ],
  69. },
  70. },
  71. });