vite.config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 AutoImport from 'unplugin-auto-import/vite'
  10. import { resolve } from "path";
  11. console.log("==", resolve(process.cwd(), "src/assets/svg"))
  12. // https://vite.dev/config/
  13. export default defineConfig({
  14. base: "./",
  15. plugins: [
  16. vue(),
  17. vueJsx(),
  18. AutoImport({
  19. imports:[
  20. 'vue',
  21. 'vue-router'
  22. ]
  23. }),
  24. // vueDevTools(),
  25. createSvgIconsPlugin({
  26. // 指定需要缓存的图标文件夹
  27. iconDirs: [ resolve(process.cwd(), "src/assets/svg")],
  28. // 指定symbolId格式
  29. symbolId: "icon-[dir]-[name]",
  30. }),
  31. codeInspectorPlugin({
  32. bundler: 'vite',
  33. }),
  34. ],
  35. resolve: {
  36. alias: {
  37. "@": fileURLToPath(new URL("./src", import.meta.url)),
  38. },
  39. },
  40. css: {
  41. // css预处理器
  42. preprocessorOptions: {
  43. less: {
  44. charset: false, // 解决中文乱码
  45. javascriptEnabled: true,
  46. additionalData:
  47. '@import "@/assets/css/global.less";@import "@/assets/css/theme.less";',
  48. },
  49. },
  50. },
  51. build: {
  52. minify: true, // 生产环境不生成sourcemap
  53. target: "es2015",
  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": {
  74. target:"https://192.168.0.59:3001",
  75. changeOrigin: true,
  76. // secure: false,
  77. }
  78. },
  79. },
  80. });