vite.config.js 2.5 KB

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