diff --git a/package.json b/package.json index 07857f1..f998424 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-refresh": "^0.4.22", "globals": "^16.4.0", + "terser": "^5.44.0", "tsx": "^4.19.2", "tw-animate-css": "^1.4.0", "typescript": "~5.9.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dd52b77..e02395f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -96,6 +96,9 @@ importers: globals: specifier: ^16.4.0 version: 16.4.0 + terser: + specifier: ^5.44.0 + version: 5.44.0 tsx: specifier: ^4.19.2 version: 4.20.6 diff --git a/vite.config.ts b/vite.config.ts index 3153584..18ad664 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -60,11 +60,15 @@ export default defineConfig({ rollupOptions: { output: { manualChunks: (id) => { - // React核心库 - if (id.includes('node_modules/react') || - id.includes('node_modules/react-dom') || - id.includes('node_modules/react-router-dom')) { - return 'react-vendor'; + // React 核心拆分得更细 + if (id.includes('node_modules/react/') && !id.includes('node_modules/react-dom')) { + return 'react-core'; + } + if (id.includes('node_modules/react-dom/')) { + return 'react-dom'; + } + if (id.includes('node_modules/react-router-dom')) { + return 'react-router'; } // Radix UI组件 if (id.includes('node_modules/@radix-ui')) { @@ -74,9 +78,26 @@ export default defineConfig({ if (id.includes('node_modules/lucide-react')) { return 'icons'; } + // 其他工具库 + if (id.includes('node_modules/')) { + return 'vendor'; + } }, }, }, + // 启用更激进的压缩 + minify: 'terser', + terserOptions: { + compress: { + drop_console: true, + drop_debugger: true, + pure_funcs: ['console.log'], + // 移除未使用的代码 + unused: true, + // 移除死代码 + dead_code: true, + }, + }, chunkSizeWarningLimit: 500, }, })