vite.config.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import path from 'path'
  4. import UnoCss from 'unocss/vite'
  5. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  6. import AutoImport from 'unplugin-auto-import/vite'
  7. import Components from 'unplugin-vue-components/vite'
  8. import IconsResolver from 'unplugin-icons/resolver'
  9. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  10. import monacoEditorPlugin from 'vite-plugin-monaco-editor'
  11. import vueJsx from '@vitejs/plugin-vue-jsx'
  12. // https://vite.dev/config/
  13. export default defineConfig(({ mode }) => {
  14. const env = loadEnv(mode, process.cwd())
  15. return {
  16. base: './',
  17. build: {
  18. outDir: 'app-agent'
  19. // rollupOptions: {
  20. // output: {
  21. // manualChunks: {
  22. // framework: ['vue', 'vue-router', 'pinia'],
  23. // element: ['element-plus', '@element-plus/icons-vue'],
  24. // monaco: ['monaco-editor'],
  25. // lexical: ['lexical', 'lexical-vue'],
  26. // echarts: ['echarts']
  27. // }
  28. // }
  29. // }
  30. },
  31. plugins: [
  32. vue(),
  33. vueJsx(),
  34. UnoCss(),
  35. createSvgIconsPlugin({
  36. // 指定存放 SVG 的文件夹
  37. iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
  38. symbolId: 'svg-icon-[dir]-[name]'
  39. }),
  40. // 代码编辑器
  41. (monacoEditorPlugin as any).default({
  42. languageWorkers: ['editorWorkerService', 'typescript', 'json', 'html', 'css']
  43. }),
  44. // 按需求加载(模板)
  45. AutoImport({
  46. imports: ['vue'],
  47. resolvers: [
  48. IconsResolver({
  49. prefix: 'Icon'
  50. }),
  51. ElementPlusResolver()
  52. ],
  53. dts: 'auto-imports.d.ts'
  54. }),
  55. Components({
  56. resolvers: [
  57. // 自动注册图标组件
  58. IconsResolver({
  59. enabledCollections: ['ep']
  60. }),
  61. ElementPlusResolver()
  62. ],
  63. dts: 'components.d.ts'
  64. }),
  65. // 修复 prismjs 全局导出和 @lexical/code 裸 Prism 引用
  66. {
  67. name: 'fix-prism-global',
  68. enforce: 'post',
  69. transform(code, id) {
  70. if (id.includes('prismjs/prism.js') || id.endsWith('/prism.js') || id.endsWith('/prism.min.js')) {
  71. if (!id.includes('components/')) {
  72. return code + '\nglobalThis.Prism = typeof Prism !== "undefined" ? Prism : {};\n export default Prism;\n';
  73. }
  74. }
  75. return null;
  76. },
  77. renderChunk(code) {
  78. if (code.includes('}(Prism)')) {
  79. return code.replace(/}\((Prism)\)/g, '}(globalThis.Prism)');
  80. }
  81. return null;
  82. }
  83. },
  84. ],
  85. resolve: {
  86. alias: {
  87. '@': path.resolve(__dirname, 'src')
  88. }
  89. },
  90. server: {
  91. host: true,
  92. port: 5174,
  93. proxy: {
  94. '/api': {
  95. target: `http://${env.VITE_BASE_URL}`,
  96. changeOrigin: true,
  97. rewrite: (path) => path.replace(/^\/api/, '/api')
  98. },
  99. '/Content': {
  100. target: `http://shalu-componenttesting-c-dev.shalu.com`,
  101. changeOrigin: true,
  102. rewrite: (path) => path.replace(/^\/Content/, '/Content')
  103. },
  104. '/Views': {
  105. target: `http://shalu-componenttesting-c-dev.shalu.com`,
  106. changeOrigin: true,
  107. rewrite: (path) => path.replace(/^\/Views/, '/Views')
  108. },
  109. '/File': {
  110. target: `http://${env.VITE_BASE_URL}`,
  111. changeOrigin: true,
  112. rewrite: (path) => path.replace(/^\/File/, '/File')
  113. },
  114. '/App': {
  115. target: `http://${env.VITE_BASE_URL}`,
  116. changeOrigin: true,
  117. rewrite: (path) => path.replace(/^\/App/, '/App')
  118. },
  119. '/_runtime': {
  120. target: `http://${env.VITE_BASE_URL}`,
  121. changeOrigin: true,
  122. rewrite: (path) => path.replace(/^\/_runtime/, '/_runtime')
  123. }
  124. }
  125. }
  126. }
  127. })