vite.config.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import topLevelAwait from 'vite-plugin-top-level-await'
  4. import { resolve } from 'path'
  5. import viteCompression from 'vite-plugin-compression' //Gzip
  6. import { visualizer } from 'rollup-plugin-visualizer'
  7. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' // 【svg-icons相关】
  8. import VitePluginHtmlEnv from 'vite-plugin-html-env'
  9. // @ts-ignore
  10. import tailwindcss from '@tailwindcss/vite'
  11. const time = new Date().getTime()
  12. export default defineConfig(({ mode, command }) => {
  13. const env = loadEnv(mode, process.cwd())
  14. const { VITE_BASE } = env
  15. return {
  16. define: {
  17. 'process.env': process.env,
  18. },
  19. plugins: [
  20. vue(),
  21. viteCompression(),
  22. VitePluginHtmlEnv(),
  23. tailwindcss(),
  24. visualizer(),
  25. createSvgIconsPlugin({
  26. // 指定需要缓存的图标文件夹
  27. iconDirs: [resolve(process.cwd(), 'src/assets/svg')],
  28. // 指定symbolId格式
  29. symbolId: 'icon-[dir]-[name]',
  30. // svgoOptions: {
  31. // plugins: [
  32. // {
  33. // name: 'removeAttrs',
  34. // params: {
  35. // attrs: ['class', 'data-name', 'fill', 'stroke']
  36. // }
  37. // }
  38. // ]
  39. // }
  40. }),
  41. topLevelAwait({
  42. promiseExportName: '__tla',
  43. promiseImportName: (i) => `__tla_${i}`,
  44. }),
  45. ],
  46. base: '/' + VITE_BASE + '/',
  47. resolve: {
  48. alias: {
  49. '@': resolve(__dirname, 'src'),
  50. },
  51. },
  52. server: {
  53. port: 9757,
  54. host: '0.0.0.0',
  55. open: true,
  56. strictPort: false,
  57. proxy: {
  58. '/dify-api': {
  59. target: 'http://1.95.78.201/',
  60. changeOrigin: true,
  61. rewrite: (path) => {
  62. return path.replace(/^\/dify-api/, '')
  63. },
  64. },
  65. [env.VITE_BASE_API_PROXY]: {
  66. target: 'http://1.95.78.201:18088/',
  67. changeOrigin: true,
  68. rewrite: (path) => path.replace(env.VITE_BASE_API_PROXY, ''),
  69. },
  70. [env.VITE_WORKFLOW_API_PROXY]: {
  71. target: 'http://1.95.78.201:18087/',
  72. changeOrigin: true,
  73. rewrite: (path) => path.replace(env.VITE_WORKFLOW_API_PROXY, ''),
  74. },
  75. },
  76. },
  77. build: {
  78. target: 'esnext',
  79. outDir: env.VITE_BASE,
  80. rollupOptions: {
  81. //分包优化
  82. output: {
  83. manualChunks(id) {
  84. if (id.includes('node_modules')) {
  85. return (
  86. time +
  87. id.toString().split('node_modules/')[1].split('/')[0].toString()
  88. )
  89. } else {
  90. return time + id.toString()
  91. }
  92. },
  93. },
  94. },
  95. },
  96. publicDir: 'src/out',
  97. optimizeDeps: {
  98. include: [],
  99. },
  100. } as any
  101. })