vite.config.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { defineConfig } from 'vite'
  2. // import vue from '@vitejs/plugin-vue'
  3. import legacy from '@vitejs/plugin-legacy'
  4. import vue from '@vitejs/plugin-vue2'
  5. import vueJsx from '@vitejs/plugin-vue2-jsx'
  6. import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  7. import { viteStaticCopy } from 'vite-plugin-static-copy'
  8. import path from 'path'
  9. const resolve = path.resolve
  10. const baseApi = 'http://llm.yangzhiqiang.tech/'
  11. const config = {
  12. base: '/openui',
  13. build: {
  14. rollupOptions: {
  15. input: {
  16. main: resolve(__dirname, 'index.html'),
  17. // mobile: resolve(__dirname, 'mobile.html'),
  18. },
  19. // output:{
  20. // manualChunks:{
  21. // 'pdfjs':['pdfjs-dist'],
  22. // 'axios':['axios'],
  23. // 'ui':['element-ui'],
  24. // 'markdown':['markdown-it-vue'],
  25. // // 'clipboard.js ':['clipboard.js']
  26. // }
  27. // }
  28. },
  29. },
  30. server: {
  31. port: 5173,
  32. host: '0.0.0.0',
  33. proxy: {
  34. '/api': {
  35. target: baseApi,
  36. changeOrigin: true,
  37. pathRewrite: {
  38. '^/api': 'api'
  39. }
  40. },
  41. '/auth': {
  42. target: baseApi,
  43. changeOrigin: true,
  44. pathRewrite: {
  45. '^/auth': 'auth'
  46. }
  47. }
  48. }
  49. },
  50. resolve: {
  51. alias: Object.entries({
  52. '@common': path.join(__dirname, 'src/common/'),
  53. '@pc': path.join(__dirname, 'src/pc/'),
  54. '@mobile': path.join(__dirname, 'src/mobile/'),
  55. '@': path.join(__dirname),
  56. }).map(([k, v]) => ({ find: k, replacement: v }))
  57. },
  58. plugins: [
  59. vue(),
  60. vueJsx(),
  61. createSvgIconsPlugin({
  62. iconDirs: [path.join(__dirname, "src/common/assets/svgIcons")], // svg文件位置
  63. symbolId: "icon-[dir]-[name]"
  64. }),
  65. viteStaticCopy({
  66. targets: [
  67. {
  68. src: 'node_modules/pdfjs-dist/cmaps',
  69. dest: ''
  70. }
  71. ]
  72. })
  73. ],
  74. }
  75. if (!process.env.IS_MODERN) {
  76. config.plugins.push(
  77. legacy({
  78. targets: ['defaults', 'ie >= 11', 'chrome 52'], //需要兼容的目标列表,可以设置多个
  79. additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
  80. renderLegacyChunks: true,
  81. polyfills: [
  82. 'es.symbol',
  83. 'es.array.filter',
  84. 'es.promise',
  85. 'es.promise.finally',
  86. 'es/map',
  87. 'es/set',
  88. 'es.array.for-each',
  89. 'es.object.define-properties',
  90. 'es.object.define-property',
  91. 'es.object.get-own-property-descriptor',
  92. 'es.object.get-own-property-descriptors',
  93. 'es.object.keys',
  94. 'es.object.to-string',
  95. 'web.dom-collections.for-each',
  96. 'esnext.global-this',
  97. 'esnext.string.match-all'
  98. ]
  99. })
  100. )
  101. }
  102. // https://vitejs.dev/config/
  103. export default defineConfig(config)