vite.config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { fileURLToPath, URL } from "node:url";
  2. import { defineConfig, loadEnv } from "vite";
  3. import vue from "@vitejs/plugin-vue";
  4. import vueDevTools from "vite-plugin-vue-devtools";
  5. import vueJsx from "@vitejs/plugin-vue-jsx";
  6. import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  7. import { codeInspectorPlugin } from "code-inspector-plugin";
  8. import AutoImport from "unplugin-auto-import/vite";
  9. import fs from "fs";
  10. import { resolve } from "path";
  11. // https://vite.dev/config/
  12. export default defineConfig(({ mode }) => {
  13. const env = loadEnv(mode, process.cwd());
  14. return {
  15. base: "./",
  16. plugins: [
  17. vue(),
  18. vueJsx(),
  19. AutoImport({
  20. imports: ["vue", "vue-router"],
  21. }),
  22. // vueDevTools(),
  23. createSvgIconsPlugin({
  24. // 指定需要缓存的图标文件夹
  25. iconDirs: [resolve(process.cwd(), "src/assets/svg")],
  26. // 指定symbolId格式
  27. symbolId: "icon-[dir]-[name]",
  28. }),
  29. codeInspectorPlugin({
  30. bundler: "vite",
  31. }),
  32. ],
  33. resolve: {
  34. alias: {
  35. "@": fileURLToPath(new URL("./src", import.meta.url)),
  36. },
  37. },
  38. css: {
  39. // css预处理器
  40. preprocessorOptions: {
  41. less: {
  42. charset: false, // 解决中文乱码
  43. javascriptEnabled: true,
  44. additionalData:
  45. '@import "@/assets/css/global.less";@import "@/assets/css/theme.less";',
  46. },
  47. },
  48. },
  49. build: {
  50. minify: true, // 生产环境不生成sourcemap
  51. target: "es2015",
  52. outDir: "dist",
  53. assetsDir: "static", // 与 index.html 中的路径匹配
  54. emptyOutDir: true,
  55. // 警报门槛,限制大文件大小
  56. chunkSizeWarningLimit: 5000,
  57. rollupOptions: {
  58. output: {
  59. chunkFileNames: "static/js/[name]-[hash].js",
  60. entryFileNames: "static/js/[name]-[hash].js",
  61. assetFileNames: "static/[ext]/[name]-[hash].[ext]",
  62. manualChunks: {
  63. vue: ["vue", "vue-router", "pinia"],
  64. ui: ["vant"],
  65. vendor: ["lodash", "axios", "dayjs"],
  66. },
  67. },
  68. },
  69. // rollupOptions: {
  70. // external: [], // 外部化处理那些你不想打包进库的依赖
  71. // // 静态资源分类打包
  72. // output: {
  73. // chunkFileNames: "static/js/[name]-[hash].js",
  74. // entryFileNames: "static/js/[name]-[hash].js",
  75. // assetFileNames: "static/[ext]/[name]-[hash].[ext]",
  76. // },
  77. // },
  78. },
  79. server: {
  80. host: true,
  81. port: 5173,
  82. open: true,
  83. cors: true,
  84. hmr: true,
  85. // https: {
  86. // key: fs.readFileSync('./certDev/key.pem'),
  87. // cert: fs.readFileSync('./certDev/cert.pem'),
  88. // },
  89. proxy: {
  90. "/api/v2": {
  91. target: env.VITE_PRO_BACKEND_PATH,
  92. changeOrigin: true,
  93. secure: true,
  94. },
  95. "/api/v1": {
  96. target: env.VITE_PRO_IM_PATH,
  97. changeOrigin: true,
  98. secure: true,
  99. },
  100. "/api": {
  101. target: env.VITE_PRO_PATH,
  102. changeOrigin: true,
  103. secure: true,
  104. },
  105. },
  106. },
  107. };
  108. });