vite.config.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import { defineConfig } from 'vite'
  2. import path from 'path'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueJsx from '@vitejs/plugin-vue-jsx'
  5. import raw from 'vite-raw-plugin'
  6. import UnoCSS from 'unocss/vite'
  7. import AutoImport from 'unplugin-auto-import/vite'
  8. import Components from 'unplugin-vue-components/vite'
  9. import Icons from 'unplugin-icons/vite'
  10. import IconsResolver from 'unplugin-icons/resolver'
  11. import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
  12. import { loadEnv } from 'vite'
  13. export default defineConfig(({ mode }) => {
  14. const env = loadEnv(mode, process.cwd())
  15. return {
  16. base: '/agentcore/',
  17. server: {
  18. port: 2048,
  19. proxy: {
  20. '/spark': {
  21. target: 'https://spark-api-open.xf-yun.com',
  22. changeOrigin: true,
  23. ws: true,
  24. rewrite: (path) => path.replace(/^\/spark/, '')
  25. },
  26. '/siliconflow': {
  27. target: 'https://api.siliconflow.cn',
  28. changeOrigin: true,
  29. ws: true,
  30. rewrite: (path) => path.replace(/^\/siliconflow/, '')
  31. },
  32. '/moonshot': {
  33. target: 'https://api.moonshot.cn',
  34. changeOrigin: true,
  35. ws: true,
  36. rewrite: (path) => path.replace(/^\/moonshot/, '')
  37. },
  38. '/deepseek': {
  39. target: 'https://api.deepseek.com',
  40. changeOrigin: true,
  41. ws: true,
  42. rewrite: (path) => path.replace(/^\/deepseek/, '')
  43. }
  44. }
  45. },
  46. plugins: [
  47. UnoCSS(),
  48. vue(),
  49. raw({
  50. fileRegex: /\.md$/
  51. }),
  52. vueJsx(),
  53. AutoImport({
  54. include: [
  55. /\.[tj]sx?$/,
  56. /\.vue\??/
  57. ],
  58. imports: [
  59. 'vue',
  60. 'vue-router',
  61. '@vueuse/core',
  62. {
  63. 'vue': [
  64. 'createVNode',
  65. 'render'
  66. ],
  67. 'vue-router': [
  68. 'createRouter',
  69. 'createWebHistory',
  70. 'useRouter',
  71. 'useRoute'
  72. ],
  73. 'uuid': [['v4', 'uuidv4']],
  74. 'lodash-es': [
  75. ['*', '_']
  76. ],
  77. 'naive-ui': [
  78. 'useDialog',
  79. 'useMessage',
  80. 'useNotification',
  81. 'useLoadingBar'
  82. ]
  83. },
  84. {
  85. from: 'vue',
  86. imports: [
  87. 'App',
  88. 'VNode',
  89. 'ComponentInternalInstance',
  90. 'GlobalComponents',
  91. 'SetupContext',
  92. 'PropType'
  93. ],
  94. type: true
  95. },
  96. {
  97. from: 'vue-router',
  98. imports: [
  99. 'RouteRecordRaw',
  100. 'RouteLocationRaw'
  101. ],
  102. type: true
  103. }
  104. ],
  105. resolvers:
  106. mode === 'development'
  107. ? []
  108. : [NaiveUiResolver()],
  109. dirs: [
  110. './src/hooks',
  111. './src/store/business',
  112. './src/store/transform'
  113. ],
  114. dts: './auto-imports.d.ts',
  115. eslintrc: {
  116. enabled: true
  117. },
  118. vueTemplate: true
  119. }),
  120. Components({
  121. directoryAsNamespace: true,
  122. collapseSamePrefixes: true,
  123. resolvers: [
  124. IconsResolver({
  125. prefix: 'auto-icon'
  126. }),
  127. NaiveUiResolver()
  128. ]
  129. }),
  130. // Auto use Iconify icon
  131. Icons({
  132. autoInstall: true,
  133. compiler: 'vue3',
  134. scale: 1.2,
  135. defaultStyle: '',
  136. defaultClass: 'unplugin-icon',
  137. jsx: 'react'
  138. })
  139. ],
  140. resolve: {
  141. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.less', '.css'],
  142. alias: [
  143. {
  144. find: '@',
  145. replacement: path.resolve(__dirname, 'src')
  146. }
  147. ]
  148. },
  149. define: {
  150. 'process.env.VITE_ROUTER_MODE': JSON.stringify(env.VITE_ROUTER_MODE)
  151. },
  152. css: {
  153. preprocessorOptions: {
  154. scss: {
  155. api: 'modern-compiler',
  156. additionalData: `@use '@/styles/naive-variables.scss' as *;`
  157. }
  158. }
  159. }
  160. }
  161. })