feat: add babel-plugin-react-compiler and configure Vite for optimized chunking

This commit is contained in:
Tunglies 2026-04-07 01:11:46 +08:00
parent 3aa39bff94
commit 1005baabe6
No known key found for this signature in database
GPG Key ID: B9B01B389469B3E8
3 changed files with 48 additions and 4 deletions

View File

@ -92,8 +92,9 @@
"@types/validator": "^13.15.10",
"@vitejs/plugin-legacy": "^8.0.0",
"@vitejs/plugin-react": "^6.0.1",
"axios": "^1.13.6",
"adm-zip": "^0.5.16",
"axios": "^1.13.6",
"babel-plugin-react-compiler": "^1.0.0",
"cli-color": "^2.0.4",
"commander": "^14.0.3",
"cross-env": "^10.1.0",

16
pnpm-lock.yaml generated
View File

@ -176,13 +176,16 @@ importers:
version: 8.0.1(terser@5.46.1)(vite@8.0.3(@emnapi/core@1.9.1)(@emnapi/runtime@1.9.1)(@types/node@24.12.0)(jiti@2.6.1)(sass@1.98.0)(terser@5.46.1)(yaml@2.8.3))
'@vitejs/plugin-react':
specifier: ^6.0.1
version: 6.0.1(vite@8.0.3(@emnapi/core@1.9.1)(@emnapi/runtime@1.9.1)(@types/node@24.12.0)(jiti@2.6.1)(sass@1.98.0)(terser@5.46.1)(yaml@2.8.3))
version: 6.0.1(babel-plugin-react-compiler@1.0.0)(vite@8.0.3(@emnapi/core@1.9.1)(@emnapi/runtime@1.9.1)(@types/node@24.12.0)(jiti@2.6.1)(sass@1.98.0)(terser@5.46.1)(yaml@2.8.3))
adm-zip:
specifier: ^0.5.16
version: 0.5.16
axios:
specifier: ^1.13.6
version: 1.14.0
babel-plugin-react-compiler:
specifier: ^1.0.0
version: 1.0.0
cli-color:
specifier: ^2.0.4
version: 2.0.4
@ -1934,6 +1937,9 @@ packages:
peerDependencies:
'@babel/core': ^7.4.0 || ^8.0.0-0 <8.0.0
babel-plugin-react-compiler@1.0.0:
resolution: {integrity: sha512-Ixm8tFfoKKIPYdCCKYTsqv+Fd4IJ0DQqMyEimo+pxUOMUR9cVPlwTrFt9Avu+3cb6Zp3mAzl+t1MrG2fxxKsxw==}
bail@2.0.2:
resolution: {integrity: sha512-0xO6mYd7JB2YesxDKplafRpsiOzPt9V02ddPCLbY1xYGPOX24NTyN50qnUxgCPcSoYMhKpAuBTjQoRZCAkUDRw==}
@ -5365,10 +5371,12 @@ snapshots:
transitivePeerDependencies:
- supports-color
'@vitejs/plugin-react@6.0.1(vite@8.0.3(@emnapi/core@1.9.1)(@emnapi/runtime@1.9.1)(@types/node@24.12.0)(jiti@2.6.1)(sass@1.98.0)(terser@5.46.1)(yaml@2.8.3))':
'@vitejs/plugin-react@6.0.1(babel-plugin-react-compiler@1.0.0)(vite@8.0.3(@emnapi/core@1.9.1)(@emnapi/runtime@1.9.1)(@types/node@24.12.0)(jiti@2.6.1)(sass@1.98.0)(terser@5.46.1)(yaml@2.8.3))':
dependencies:
'@rolldown/pluginutils': 1.0.0-rc.7
vite: 8.0.3(@emnapi/core@1.9.1)(@emnapi/runtime@1.9.1)(@types/node@24.12.0)(jiti@2.6.1)(sass@1.98.0)(terser@5.46.1)(yaml@2.8.3)
optionalDependencies:
babel-plugin-react-compiler: 1.0.0
acorn-jsx@5.3.2(acorn@8.16.0):
dependencies:
@ -5452,6 +5460,10 @@ snapshots:
transitivePeerDependencies:
- supports-color
babel-plugin-react-compiler@1.0.0:
dependencies:
'@babel/types': 7.29.0
bail@2.0.2: {}
balanced-match@4.0.4: {}

View File

@ -10,7 +10,11 @@ export default defineConfig({
server: { port: 3000 },
plugins: [
svgr(),
react(),
react({
babel: {
plugins: ['babel-plugin-react-compiler'],
},
} as any),
legacy({
modernTargets: ['edge>=109', 'safari>=14'],
renderLegacyChunks: false,
@ -26,6 +30,24 @@ export default defineConfig({
outDir: '../dist',
emptyOutDir: true,
chunkSizeWarningLimit: 4000,
rollupOptions: {
output: {
manualChunks: (id) => {
if (id.includes('monaco-yaml')) return 'monaco-yaml'
if (
id.includes('node_modules/react/') ||
id.includes('node_modules/react-dom/')
)
return 'react'
if (id.includes('node_modules/react-router')) return 'router'
if (
id.includes('node_modules/i18next') ||
id.includes('node_modules/react-i18next')
)
return 'i18n'
},
},
},
},
resolve: {
alias: {
@ -36,4 +58,13 @@ export default defineConfig({
define: {
OS_PLATFORM: `"${process.platform}"`,
},
optimizeDeps: {
include: [
'react',
'react-dom',
'react-router-dom',
'i18next',
'react-i18next',
],
},
})