vite.config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. console.log(env.VITE_PRO_IM_PATH)
  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. // 警报门槛,限制大文件大小
  53. chunkSizeWarningLimit: 5000,
  54. rollupOptions: {
  55. external: [], // 外部化处理那些你不想打包进库的依赖
  56. // 静态资源分类打包
  57. output: {
  58. chunkFileNames: "static/js/[name]-[hash].js",
  59. entryFileNames: "static/js/[name]-[hash].js",
  60. assetFileNames: "static/[ext]/[name]-[hash].[ext]",
  61. },
  62. },
  63. },
  64. server: {
  65. host: true,
  66. port: 5173,
  67. open: true,
  68. cors: true,
  69. hmr: true,
  70. proxy: {
  71. "/api/v1": {
  72. target: env.VITE_PRO_IM_PATH,
  73. changeOrigin: true,
  74. secure: true,
  75. },
  76. "/api": {
  77. target: env.VITE_PRO_PATH,
  78. changeOrigin: true,
  79. secure: true,
  80. },
  81. },
  82. },
  83. };
  84. });