vite.config.js 4.4 KB

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