vite.config.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { fileURLToPath, URL } from "node:url";
  2. import { defineConfig, loadEnv } from "vite";
  3. import vue from "@vitejs/plugin-vue";
  4. import AutoImport from "unplugin-auto-import/vite";
  5. import Components from "unplugin-vue-components/vite";
  6. import Icons from "unplugin-icons/vite";
  7. import { ElementPlusResolver, VueUseComponentsResolver, VueUseDirectiveResolver } from "unplugin-vue-components/resolvers";
  8. import IconsResolver from "unplugin-icons/resolver";
  9. import { FileSystemIconLoader } from "unplugin-icons/loaders";
  10. import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  11. import path from "path";
  12. // https://vitejs.dev/config/
  13. export default defineConfig(({ mode }) => {
  14. const viteEnv = loadEnv(mode, "./");
  15. return {
  16. base: viteEnv.VITE_BASE,
  17. server: {
  18. host: "0.0.0.0",
  19. port: "8080",
  20. open: false,
  21. strictPort: true,
  22. cors: true,
  23. proxy: {
  24. [viteEnv.VITE_BASE_URL]: {
  25. target: viteEnv.VITE_BASE_SERVER_URL,
  26. changeOrigin: true,
  27. rewrite: path => path.replace(viteEnv.VITE_BASE_URL, "/")
  28. },
  29. // "/api": {
  30. // target: "http://qdport.gateway.10.236.3.36.nip.io",
  31. // changeOrigin: true,
  32. // rewrite: path => path.replace("/api", "/")
  33. // }
  34. }
  35. },
  36. build: {
  37. outDir: "dist",
  38. assetsDir: "static/assets",
  39. chunkSizeWarningLimit: 2000,
  40. rollupOptions: {
  41. output: {
  42. chunkFileNames: "static/js/[name]-[hash].js",
  43. entryFileNames: "static/js/[name]-[hash].js",
  44. assetFileNames: "static/[ext]/[name]-[hash].[ext]"
  45. }
  46. }
  47. },
  48. resolve: {
  49. alias: {
  50. "~": path.resolve(__dirname, "./"),
  51. "@": path.resolve(__dirname, "./src")
  52. }
  53. },
  54. css: {
  55. preprocessorOptions: {
  56. scss: {
  57. additionalData: '@import "@/assets/style/variable.scss";'
  58. }
  59. }
  60. },
  61. plugins: [
  62. vue({
  63. template: {
  64. compilerOptions: {
  65. isCustomElement: tag => /^micro-app/.test(tag)
  66. }
  67. }
  68. }),
  69. AutoImport({
  70. include: [
  71. /\.[tj]sx?$/,
  72. /\.vue$/,
  73. /\.vue\?vue/,
  74. /\.md$/
  75. ],
  76. imports: ["vue", "pinia", "vue-router", "@vueuse/core"],
  77. eslintrc: {
  78. enabled: true,
  79. filepath: "./.eslintrc-auto-import.json",
  80. globalsPropValue: true
  81. },
  82. resolvers: [
  83. ElementPlusResolver(),
  84. IconsResolver({ componentPrefix: "tjm-icon", enabledCollections: ["ep", "home", "user"] })
  85. ]
  86. }),
  87. Components({
  88. dirs: ["src/components/", "src/view/"],
  89. include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
  90. resolvers: [
  91. ElementPlusResolver(),
  92. VueUseComponentsResolver(),
  93. VueUseDirectiveResolver(),
  94. IconsResolver({
  95. prefix: "tjm-icon",
  96. customCollections: ["ep", "home", "user"]
  97. })
  98. ]
  99. }),
  100. // 静态Icon 插件配置 https://icones.js.org/ https://icones.netlify.app/ vscode插件Iconify IntelliSense
  101. Icons({
  102. compiler: "vue3",
  103. customCollections: {
  104. home: FileSystemIconLoader("src/assets/svg/home", (svg) => svg.replace(/^<svg /, '<svg fill="currentColor" ')),
  105. user: FileSystemIconLoader("src/assets/svg/user", (svg) => svg.replace(/^<svg /, '<svg fill="currentColor" '))
  106. },
  107. autoInstall: true
  108. }),
  109. createSvgIconsPlugin({
  110. iconDirs: [path.resolve(process.cwd(), "src/assets/svg")],
  111. symbolId: "icon-[dir]-[name]",
  112. svgoOptions: true
  113. })
  114. ]
  115. }
  116. });