vite.config.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. export default defineConfig({
  11. define: {
  12. 'process.env': process.env
  13. },
  14. plugins: [
  15. vue(),
  16. viteCompression(),
  17. VitePluginHtmlEnv(),
  18. visualizer(),
  19. createSvgIconsPlugin({
  20. // 指定需要缓存的图标文件夹
  21. iconDirs: [resolve(process.cwd(), 'src/assets/svg')],
  22. // 指定symbolId格式
  23. symbolId: 'icon-[dir]-[name]',
  24. // svgoOptions: {
  25. // plugins: [
  26. // {
  27. // name: 'removeAttrs',
  28. // params: {
  29. // attrs: ['class', 'data-name', 'fill', 'stroke']
  30. // }
  31. // }
  32. // ]
  33. // }
  34. }),
  35. topLevelAwait({
  36. promiseExportName: '__tla',
  37. promiseImportName: i => `__tla_${i}`
  38. })
  39. ],
  40. base: '/',
  41. resolve: {
  42. alias: {
  43. '@': resolve(__dirname, 'src'),
  44. },
  45. },
  46. server: {
  47. port: 8090,
  48. open: false,
  49. strictPort: false,
  50. proxy: {
  51. '/mock-api': {
  52. target: 'https://www.fastmock.site/mock/002bd20e30dcef8f255675f80a50382c/mock',
  53. changeOrigin: true,
  54. rewrite: (path) => {
  55. return path.replace(/^\/mock-api/, '')
  56. }
  57. }
  58. }
  59. },
  60. build: {
  61. outDir: "tszwfw-mobile",
  62. rollupOptions: {//分包优化
  63. output: {
  64. manualChunks(id) {
  65. if (id.includes('node_modules')) {
  66. return time + id.toString().split('node_modules/')[1].split('/')[0].toString();
  67. } else {
  68. return time + id.toString();
  69. }
  70. }
  71. }
  72. }
  73. },
  74. publicDir: 'src/out',
  75. optimizeDeps: {
  76. include: []
  77. }
  78. })