vite.config.js 2.2 KB

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