vite.config.js 1.9 KB

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