vite.config.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { fileURLToPath, URL } from 'node:url'
  2. import path from 'path'
  3. import { defineConfig, loadEnv } from 'vite'
  4. import vue from '@vitejs/plugin-vue'
  5. import vueJsx from '@vitejs/plugin-vue-jsx'
  6. import AutoImport from 'unplugin-auto-import/vite'
  7. import Components from 'unplugin-vue-components/vite'
  8. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  9. import { createStyleImportPlugin, VxeTableResolve } from 'vite-plugin-style-import'
  10. import Unocss from 'unocss/vite'
  11. import VueDevTools from 'vite-plugin-vue-devtools'
  12. import { lazyImport, VxeResolver } from 'vite-plugin-lazy-import'
  13. import esLintPlugin from 'vite-plugin-eslint'
  14. export default defineConfig(({ mode }) => {
  15. const env = loadEnv(mode, process.cwd(), '')
  16. return {
  17. base: '/',
  18. plugins: [
  19. vue(),
  20. vueJsx(),
  21. Unocss(),
  22. VueDevTools(),
  23. esLintPlugin({
  24. emitError: true
  25. }),
  26. AutoImport({
  27. imports: ['vue', 'vue-router', 'pinia', '@vueuse/core'],
  28. dts: 'src/auto-import.d.ts'
  29. }),
  30. Components({
  31. dirs: ['src/components'],
  32. extensions: ['vue'],
  33. dts: 'src/components.d.ts'
  34. }),
  35. createSvgIconsPlugin({
  36. iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
  37. symbolId: 'icon-[dir]-[name]'
  38. }),
  39. createStyleImportPlugin({
  40. resolves: [VxeTableResolve()]
  41. }),
  42. lazyImport({
  43. resolvers: [
  44. VxeResolver({
  45. libraryName: 'vxe-table'
  46. }),
  47. VxeResolver({
  48. libraryName: 'vxe-pc-ui'
  49. })
  50. ]
  51. })
  52. ],
  53. resolve: {
  54. alias: {
  55. '@': fileURLToPath(new URL('./src', import.meta.url))
  56. }
  57. },
  58. server: {
  59. proxy: {
  60. [env.VITE_BASE_API]: {
  61. target: env.VITE_BASE_PATH,
  62. changeOrigin: true
  63. }
  64. },
  65. hmr: {
  66. overlay: true
  67. }
  68. },
  69. build: {
  70. rollupOptions: {
  71. output: {
  72. manualChunks: {
  73. vueChunk: ['vue', 'vue-router', 'pinia', '@vueuse/core'],
  74. elementPlusChunk: ['element-plus', '@element-plus/icons-vue'],
  75. mapChunk: ['@amap/amap-jsapi-loader'],
  76. fsChunk: ['@fskj-admin/core', '@fskj-admin/micro'],
  77. tableChunk: ['vxe-table', 'vxe-pc-ui', 'xe-utils', '@vxe-ui/plugin-render-element'],
  78. editorChunk: ['@wangeditor-next/editor', '@wangeditor-next/editor-for-vue'],
  79. otherChunk: ['axios', 'dayjs', 'wujie-vue3']
  80. }
  81. }
  82. }
  83. }
  84. }
  85. })