vite.config.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. }
  51. },
  52. build: {
  53. outDir: "duty",
  54. rollupOptions: {//分包优化
  55. output: {
  56. manualChunks(id) {
  57. if (id.includes('node_modules')) {
  58. return time + id.toString().split('node_modules/')[1].split('/')[0].toString();
  59. } else {
  60. return time + id.toString();
  61. }
  62. // if(id.indexOf('node_modules') > -1) {
  63. // return 'vendor'
  64. // }
  65. }
  66. }
  67. }
  68. },
  69. publicDir: 'src/out',
  70. optimizeDeps: {
  71. include: []
  72. }
  73. })