vite.config.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. const time = new Date().getTime()
  10. export default defineConfig(({mode, command}) => {
  11. const env = loadEnv(mode, process.cwd())
  12. const { VITE_BASE } = env
  13. return {
  14. define: {
  15. 'process.env': process.env
  16. },
  17. plugins: [
  18. vue(),
  19. viteCompression(),
  20. VitePluginHtmlEnv(),
  21. visualizer(),
  22. createSvgIconsPlugin({
  23. // 指定需要缓存的图标文件夹
  24. iconDirs: [resolve(process.cwd(), 'src/assets/svg')],
  25. // 指定symbolId格式
  26. symbolId: 'icon-[dir]-[name]',
  27. // svgoOptions: {
  28. // plugins: [
  29. // {
  30. // name: 'removeAttrs',
  31. // params: {
  32. // attrs: ['class', 'data-name', 'fill', 'stroke']
  33. // }
  34. // }
  35. // ]
  36. // }
  37. }),
  38. topLevelAwait({
  39. promiseExportName: '__tla',
  40. promiseImportName: i => `__tla_${i}`
  41. })
  42. ],
  43. base: '/' + VITE_BASE + '/',
  44. resolve: {
  45. alias: {
  46. '@': resolve(__dirname, 'src'),
  47. },
  48. },
  49. server: {
  50. port: 9616,
  51. host: '0.0.0.0',
  52. open: true,
  53. strictPort: false,
  54. proxy: {
  55. '/dify-api': {
  56. target: 'http://1.95.78.201/',
  57. changeOrigin: true,
  58. rewrite: (path) => {
  59. return path.replace(/^\/dify-api/, '')
  60. }
  61. },
  62. '/cms-api': {
  63. target: 'http://192.168.5.98:8090/',
  64. // target: 'http://192.168.4.12:8090/',
  65. changeOrigin: true,
  66. rewrite: (path) => {
  67. return path.replace(/^\/cms-api/, '')
  68. }
  69. },
  70. }
  71. },
  72. build: {
  73. target: 'esnext',
  74. outDir: "smart-ask-answer-web",
  75. rollupOptions: {//分包优化
  76. output: {
  77. manualChunks(id) {
  78. if (id.includes('node_modules')) {
  79. return time + id.toString().split('node_modules/')[1].split('/')[0].toString();
  80. } else {
  81. return time + id.toString();
  82. }
  83. }
  84. }
  85. }
  86. },
  87. publicDir: 'src/out',
  88. optimizeDeps: {
  89. include: []
  90. }
  91. } as any
  92. })