vite.config.js 2.8 KB

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