vite.config.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. api: 'modern-compiler', // 修改api调用方式
  60. additionalData: `@use "@/assets/style/variable.scss" as *;` // 导出全局变量和 mixin
  61. }
  62. }
  63. },
  64. plugins: [
  65. topLevelAwait(),
  66. vue({
  67. template: {
  68. compilerOptions: {
  69. isCustomElement: tag => /^micro-app/.test(tag)
  70. }
  71. }
  72. }),
  73. AutoImport({
  74. include: [
  75. /\.[tj]sx?$/,
  76. /\.vue$/,
  77. /\.vue\?vue/,
  78. /\.md$/
  79. ],
  80. imports: ["vue", "pinia", "vue-router", "@vueuse/core"],
  81. eslintrc: {
  82. enabled: true,
  83. filepath: "./.eslintrc-auto-import.json",
  84. globalsPropValue: true
  85. },
  86. resolvers: [
  87. ElementPlusResolver(),
  88. IconsResolver({ componentPrefix: "tjm-icon", enabledCollections: ["ep", "home", "user"] })
  89. ]
  90. }),
  91. Components({
  92. dirs: ["src/components/", "src/view/"],
  93. include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
  94. resolvers: [
  95. ElementPlusResolver(),
  96. VueUseComponentsResolver(),
  97. VueUseDirectiveResolver(),
  98. IconsResolver({
  99. prefix: "tjm-icon",
  100. customCollections: ["ep", "home", "user"]
  101. })
  102. ]
  103. }),
  104. // 静态Icon 插件配置 https://icones.js.org/ https://icones.netlify.app/ vscode插件Iconify IntelliSense
  105. Icons({
  106. compiler: "vue3",
  107. customCollections: {
  108. home: FileSystemIconLoader("src/assets/svg/home", (svg) => svg.replace(/^<svg /, '<svg fill="currentColor" ')),
  109. user: FileSystemIconLoader("src/assets/svg/user", (svg) => svg.replace(/^<svg /, '<svg fill="currentColor" '))
  110. },
  111. autoInstall: true
  112. }),
  113. createSvgIconsPlugin({
  114. iconDirs: [path.resolve(process.cwd(), "src/assets/svg")],
  115. symbolId: "icon-[dir]-[name]",
  116. svgoOptions: true
  117. })
  118. ]
  119. }
  120. });