vite.config.ts 4.0 KB

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