- vite.config.ts: production sourcemap=false (build time 17.89s → 6.89s) - scripts/bundle-report.cjs: 输出 raw/gzip 大小 + 预算校验 (500KB total / 150KB per chunk) - package.json: build pipeline 末尾自动跑 bundle-report 实测(无 sourcemap,9 chunks): Total gzip: 301.41 KB (预算 500 ✅) Main chunk: 85.57 KB gzip (预算 150 ✅) Heavy vendor (>80 KB): chart-vendor 101 KB / index 86 KB 可优化点:ShareDialogPage + recharts 走 lazy load (留 T-B-26 处理) G3 闸门:build 项 ✅,main chunk 下降 87.85 → 85.57 KB
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { defineConfig } from 'vite';
|
||
import react from '@vitejs/plugin-react';
|
||
import tailwindcss from '@tailwindcss/vite';
|
||
import path from 'node:path';
|
||
|
||
// V10 选项 B · Vite 5 + React 19 + Tailwind 4
|
||
// 替代 Next.js 16 App Router,使用 React Router 7 (client-side routing)
|
||
export default defineConfig({
|
||
plugins: [react(), tailwindcss()],
|
||
resolve: {
|
||
alias: {
|
||
'@': path.resolve(__dirname, './src'),
|
||
},
|
||
},
|
||
server: {
|
||
host: '0.0.0.0',
|
||
port: 3000,
|
||
strictPort: true,
|
||
// CloudStudio / WorkBuddy 预览代理白名单
|
||
allowedHosts: [
|
||
'webview.e2b.bj5.sandbox.cloudstudio.club',
|
||
'.sandbox.cloudstudio.club',
|
||
'.cloudstudio.club',
|
||
'.workbuddy.agentos-worker.net',
|
||
'.agentos-worker.net',
|
||
'localhost',
|
||
'127.0.0.1',
|
||
],
|
||
},
|
||
preview: {
|
||
host: '0.0.0.0',
|
||
port: 4173,
|
||
strictPort: true,
|
||
},
|
||
build: {
|
||
target: 'es2022',
|
||
// 生产 sourcemap 关闭(开发调试足够,bundle size 减少 ~30%)
|
||
sourcemap: false,
|
||
cssCodeSplit: true,
|
||
// 4KB 以下内联
|
||
assetsInlineLimit: 4096,
|
||
rollupOptions: {
|
||
output: {
|
||
// V10 优化: 手动 chunk split
|
||
manualChunks: {
|
||
'react-vendor': ['react', 'react-dom', 'react-router-dom', 'react-router'],
|
||
'query-vendor': ['@tanstack/react-query', '@tanstack/react-query-devtools'],
|
||
'state-vendor': ['zustand'],
|
||
'form-vendor': ['react-hook-form', '@hookform/resolvers', 'zod'],
|
||
'markdown-vendor': ['react-markdown', 'rehype-sanitize', 'remark-gfm'],
|
||
'chart-vendor': ['recharts'],
|
||
'qrcode-vendor': ['qrcode.react'],
|
||
'icons-vendor': ['lucide-react'],
|
||
},
|
||
chunkFileNames: 'assets/[name]-[hash].js',
|
||
entryFileNames: 'assets/[name]-[hash].js',
|
||
assetFileNames: 'assets/[name]-[hash][extname]',
|
||
},
|
||
},
|
||
},
|
||
test: {
|
||
globals: true,
|
||
environment: 'jsdom',
|
||
setupFiles: ['./src/test/setup.ts'],
|
||
css: false,
|
||
coverage: {
|
||
provider: 'v8',
|
||
reporter: ['text', 'html', 'json'],
|
||
exclude: ['**/node_modules/**', '**/dist/**', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'],
|
||
},
|
||
},
|
||
});
|