perf: 优化 Vite 构建配置降低内存使用 - 移除生产环境visualizer插件

This commit is contained in:
2026-04-20 06:28:56 +08:00
parent bed73618d6
commit e505ccd76e
2 changed files with 9 additions and 8 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "NODE_OPTIONS=--max-old-space-size=8192 tsc && vite build", "build": "NODE_OPTIONS=--max-old-space-size=6144 tsc && vite build",
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
+8 -7
View File
@@ -25,12 +25,12 @@ export default defineConfig(({mode}) => {
VitePWA({ VitePWA({
registerType: 'autoUpdate', registerType: 'autoUpdate',
workbox: { workbox: {
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024, // 10MB maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
navigateFallbackDenylist: [/^\/api\//], // 阻止 /api 被 fallback 到 index.html navigateFallbackDenylist: [/^\/api\//],
runtimeCaching: [ runtimeCaching: [
{ {
urlPattern: ({url}) => !url.pathname.startsWith('/api/'), urlPattern: ({url}) => !url.pathname.startsWith('/api/'),
handler: 'NetworkOnly', // 不缓存,直接请求网络 handler: 'NetworkOnly',
}, },
], ],
}, },
@@ -49,10 +49,9 @@ export default defineConfig(({mode}) => {
] ]
}, },
}) })
] : []), ] : [
visualizer({ visualizer({}) as unknown as PluginOption
// open: true, ]),
}) as unknown as PluginOption
], ],
resolve: { resolve: {
alias: {'@': resolve(__dirname, './src')}, alias: {'@': resolve(__dirname, './src')},
@@ -60,6 +59,8 @@ export default defineConfig(({mode}) => {
build: { build: {
sourcemap: false, sourcemap: false,
minify: 'esbuild', minify: 'esbuild',
target: 'es2020',
chunkSizeWarningLimit: 2000,
rollupOptions: { rollupOptions: {
maxParallelFileOps: 2, maxParallelFileOps: 2,
output: { output: {