vite.config.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { defineConfig } 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. // @ts-ignore
  11. const apiProxyVersion = 'local'
  12. // https://vitejs.dev/config/
  13. export default defineConfig({
  14. define: {
  15. 'process.env': process.env
  16. },
  17. plugins: [vue(), viteCompression(), VitePluginHtmlEnv(), visualizer(), createSvgIconsPlugin({
  18. // 指定需要缓存的图标文件夹
  19. iconDirs: [resolve(process.cwd(), 'src/assets/svg')],
  20. // 指定symbolId格式
  21. symbolId: 'icon-[dir]-[name]',
  22. }), topLevelAwait({
  23. promiseExportName: '__tla',
  24. promiseImportName: i => `__tla_${i}`
  25. })],
  26. base: '/',
  27. resolve: {
  28. alias: {
  29. '@': resolve(__dirname, 'src'),
  30. '~@': resolve(__dirname, 'src'),
  31. '@views': resolve(__dirname, 'src/views'),
  32. '@components': resolve(__dirname, 'src/components')
  33. },
  34. },
  35. server: {
  36. port: 8686,
  37. // open: true,
  38. https: false,
  39. host: '0.0.0.0',
  40. strictPort: false,
  41. proxy: {
  42. '/api-ztpt/': {
  43. target: 'http://127.0.0.1:3001/',
  44. // target: 'http://10.110.35.47/',
  45. changeOrigin: true,
  46. rewrite: path => {
  47. return path.replace(/^\/api-ztpt/, '')
  48. }
  49. },
  50. '/api/': {
  51. target: 'http://8.140.240.182:18091/',
  52. changeOrigin: true,
  53. rewrite: path => {
  54. return path.replace(/^\/api/, '')
  55. }
  56. },
  57. }
  58. },
  59. build: {
  60. outDir: "duty",
  61. rollupOptions: {//分包优化
  62. output: {
  63. manualChunks(id) {
  64. if (id.includes('node_modules')) {
  65. return time + id.toString().split('node_modules/')[1].split('/')[0].toString();
  66. } else {
  67. return time + id.toString();
  68. }
  69. // if(id.indexOf('node_modules') > -1) {
  70. // return 'vendor'
  71. // }
  72. }
  73. }
  74. }
  75. },
  76. publicDir: 'src/out',
  77. optimizeDeps: {
  78. include: []
  79. }
  80. })