perf(build): 优化开发预热与首屏分包懒加载

减少应用启动时的静态依赖,增加首屏体积预算与懒加载边界校验。验证通过:875 项单测、UI 依赖审计、ESLint、Prettier、生产构建与首屏产物校验;Chrome 模拟回归通过。
This commit is contained in:
zhanjunhao
2026-11-20 15:03:30 +08:00
parent 03276c5207
commit b3f4711d20
14 changed files with 161 additions and 33 deletions
+14 -1
View File
@@ -15,6 +15,7 @@ const DEV_PROXY_TARGET = 'http://134.175.227.134:13000';
* 这是既有行为,保持不变;若要收紧为「只匹配项目 src 目录」,属于独立变更。
*/
const JSX_IN_JS_RE = /src\/.*\.js$/;
const REACT_RUNTIME_RE = /\/node_modules\/(?:react|react-dom|scheduler)\//;
/**
* 让 JSX_IN_JS_RE 命中的 .js 按 JSX 语法解析。
@@ -25,7 +26,7 @@ function jsxInJsPlugin() {
return {
name: 'treat-js-files-as-jsx',
async transform(code, id) {
if (!JSX_IN_JS_RE.test(id)) {
if (!JSX_IN_JS_RE.test(id) || !code.includes('<')) {
return null;
}
@@ -131,8 +132,13 @@ export default defineConfig(({ mode, command }) => {
target: 'es2015',
// 生产环境不需要 sourcemap
sourcemap: false,
reportCompressedSize: false,
rollupOptions: {
output: {
onlyExplicitManualChunks: true,
manualChunks(id) {
if (REACT_RUNTIME_RE.test(id)) return 'react-runtime';
},
// 文件名带内容 hash,便于浏览器长期缓存与增量更新
chunkFileNames: 'assets/[name]-[hash].js',
entryFileNames: 'assets/[name]-[hash].js',
@@ -144,6 +150,13 @@ export default defineConfig(({ mode, command }) => {
// 监听所有网卡,便于局域网与容器内访问
host: '0.0.0.0',
port: '5174',
warmup: {
clientFiles: [
'./src/index.jsx',
'./src/components/layout/PageLayout.jsx',
'./src/App.jsx',
],
},
// Browser reports contain HTML; watching them would reload active acceptance pages.
watch: {
ignored: [