vite.config.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { fileURLToPath, URL } from "node:url";
  2. import fs from 'node:fs';
  3. import { defineConfig } from "vite";
  4. import vue from "@vitejs/plugin-vue";
  5. import vueDevTools from "vite-plugin-vue-devtools";
  6. import vueJsx from "@vitejs/plugin-vue-jsx";
  7. import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  8. import { codeInspectorPlugin } from 'code-inspector-plugin';
  9. import { resolve } from "path";
  10. console.log("==", resolve(process.cwd(), "src/assets/svg"))
  11. // https://vite.dev/config/
  12. export default defineConfig({
  13. base: "./",
  14. plugins: [
  15. vue(),
  16. vueJsx(),
  17. // vueDevTools(),
  18. createSvgIconsPlugin({
  19. // 指定需要缓存的图标文件夹
  20. iconDirs: [ resolve(process.cwd(), "src/assets/svg")],
  21. // 指定symbolId格式
  22. symbolId: "icon-[dir]-[name]",
  23. }),
  24. codeInspectorPlugin({
  25. bundler: 'vite',
  26. }),
  27. ],
  28. resolve: {
  29. alias: {
  30. "@": fileURLToPath(new URL("./src", import.meta.url)),
  31. },
  32. },
  33. css: {
  34. // css预处理器
  35. preprocessorOptions: {
  36. less: {
  37. charset: false, // 解决中文乱码
  38. javascriptEnabled: true,
  39. additionalData:
  40. '@import "@/assets/css/global.less";@import "@/assets/css/theme.less";',
  41. },
  42. },
  43. },
  44. build: {
  45. minify: true, // 生产环境不生成sourcemap
  46. target: "es2015",
  47. // 警报门槛,限制大文件大小
  48. chunkSizeWarningLimit: 5000,
  49. rollupOptions: {
  50. external: [], // 外部化处理那些你不想打包进库的依赖
  51. // 静态资源分类打包
  52. output: {
  53. chunkFileNames: "static/js/[name]-[hash].js",
  54. entryFileNames: "static/js/[name]-[hash].js",
  55. assetFileNames: "static/[ext]/[name]-[hash].[ext]",
  56. },
  57. },
  58. },
  59. server: {
  60. host: true,
  61. port: 5173,
  62. open: true,
  63. cors: true,
  64. hmr: true,
  65. proxy: {
  66. "^/api": {
  67. target:"https://192.168.0.59:3001",
  68. changeOrigin: true,
  69. // secure: false,
  70. }
  71. },
  72. },
  73. });