diff --git a/docs/docs/docs/api/config.md b/docs/docs/docs/api/config.md index 5cb7d530f140..ee855056eb10 100644 --- a/docs/docs/docs/api/config.md +++ b/docs/docs/docs/api/config.md @@ -690,6 +690,24 @@ favicons: [ ] ``` +## forget + +- 类型:`{ ReactCompilerConfig: object }` +- 默认值:`null` + +是否开启 React Compiler(React Forget)功能。参考 https://react.dev/learn/react-compiler 。 + +```ts +forget: { + ReactCompilerConfig: {}, +}, +``` + +注意: + +1、forget 和 mfsu、mako 暂时不兼容,如果开启了 forget,同时 mfsu、mako 有打开时会抛错。 +2、forget 需要 react 19,使用时,请手动安装 react@rc 和 react-dom@rc 到项目依赖。 + ## forkTSChecker - 类型:`object` diff --git a/packages/preset-umi/package.json b/packages/preset-umi/package.json index def327a5ca11..2037128378ee 100644 --- a/packages/preset-umi/package.json +++ b/packages/preset-umi/package.json @@ -46,6 +46,7 @@ "@umijs/utils": "workspace:*", "@umijs/zod2ts": "workspace:*", "babel-plugin-dynamic-import-node": "2.3.3", + "babel-plugin-react-compiler": "0.0.0-experimental-c23de8d-20240515", "click-to-react-component": "^1.0.8", "core-js": "3.34.0", "current-script-polyfill": "1.0.0", diff --git a/packages/preset-umi/src/features/forget/forget.ts b/packages/preset-umi/src/features/forget/forget.ts new file mode 100644 index 000000000000..4c42b4509aed --- /dev/null +++ b/packages/preset-umi/src/features/forget/forget.ts @@ -0,0 +1,48 @@ +import { IApi } from '../../types'; + +export default (api: IApi) => { + api.describe({ + key: 'forget', + config: { + schema({ zod }) { + return zod.object({ + ReactCompilerConfig: zod.object({}).optional(), + }); + }, + }, + enableBy: api.EnableBy.config, + }); + + api.onCheckConfig(() => { + if (api.config.mfsu) { + throw new Error( + `forget is not compatible with mfsu, please disable mfsu first.`, + ); + } + if (api.config.mako) { + throw new Error( + `forget is not compatible with mako, please disable mako first.`, + ); + } + }); + + api.onCheck(() => { + let reactMajorVersion = api.appData.react.version.split('.')[0]; + if (reactMajorVersion < 19) { + throw new Error( + `forget is only compatible with React 19 and above, please upgrade your React version.`, + ); + } + }); + + api.modifyConfig((memo) => { + let ReactCompilerConfig = api.userConfig.forget.ReactCompilerConfig || {}; + return { + ...memo, + extraBabelPlugins: [ + ...(memo.extraBabelPlugins || []), + [require.resolve('babel-plugin-react-compiler'), ReactCompilerConfig], + ], + }; + }); +}; diff --git a/packages/preset-umi/src/index.ts b/packages/preset-umi/src/index.ts index 0c428990ee83..8b12a88c7e5f 100644 --- a/packages/preset-umi/src/index.ts +++ b/packages/preset-umi/src/index.ts @@ -60,6 +60,7 @@ export default () => { require.resolve('./features/mako/mako'), require.resolve('./features/hmrGuardian/hmrGuardian'), require.resolve('./features/routePreloadOnLoad/routePreloadOnLoad'), + require.resolve('./features/forget/forget'), // commands require.resolve('./commands/build'), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6da4e9b0fed5..de2cdfcdff27 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2458,6 +2458,9 @@ importers: babel-plugin-dynamic-import-node: specifier: 2.3.3 version: 2.3.3 + babel-plugin-react-compiler: + specifier: 0.0.0-experimental-c23de8d-20240515 + version: 0.0.0-experimental-c23de8d-20240515 click-to-react-component: specifier: ^1.0.8 version: 1.0.8(@types/react@18.0.26)(react-dom@18.1.0)(react@18.1.0) @@ -5429,7 +5432,7 @@ packages: dependencies: '@ampproject/remapping': 2.2.0 '@babel/code-frame': 7.22.13 - '@babel/generator': 7.23.0 + '@babel/generator': 7.23.6 '@babel/helper-compilation-targets': 7.22.15 '@babel/helper-module-transforms': 7.23.3(@babel/core@7.23.0) '@babel/helpers': 7.23.1 @@ -5547,6 +5550,16 @@ packages: jsesc: 2.5.2 dev: true + /@babel/generator@7.2.0: + resolution: {integrity: sha512-BA75MVfRlFQG2EZgFYIwyT1r6xSkwfP2bdkY/kLZusEYWiJs4xCowab/alaEaT0wSvmVuXGqiefeBlP+7V1yKg==} + dependencies: + '@babel/types': 7.23.6 + jsesc: 2.5.2 + lodash: 4.17.21 + source-map: 0.5.7 + trim-right: 1.0.1 + dev: false + /@babel/generator@7.20.7: resolution: {integrity: sha512-7wqMOJq8doJMZmP4ApXTzLxSr7+oO2jroJURrVEp6XShrQUObV8Tq/D0NCcoYg2uHqUrjzO0zwBjoYzelxK+sw==} engines: {node: '>=6.9.0'} @@ -5565,15 +5578,6 @@ packages: '@jridgewell/trace-mapping': 0.3.20 jsesc: 2.5.2 - /@babel/generator@7.23.0: - resolution: {integrity: sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/types': 7.23.6 - '@jridgewell/gen-mapping': 0.3.3 - '@jridgewell/trace-mapping': 0.3.20 - jsesc: 2.5.2 - /@babel/generator@7.23.6: resolution: {integrity: sha512-qrSfCYxYQB5owCmGLbl8XRpX1ytXlpueOb0N0UmQwA073KZxejgQTzAmJezxvpwQD9uGtK2shHdi55QT+MbjIw==} engines: {node: '>=6.9.0'} @@ -13576,6 +13580,15 @@ packages: transitivePeerDependencies: - supports-color + /@jest/types@24.9.0: + resolution: {integrity: sha512-XKK7ze1apu5JWQ5eZjHITP66AX+QsLlbaJRBGYr8pNzwcAE2JVkwnf0yqjHTsDRcjR0mujy/NmZMXw5kl+kGBw==} + engines: {node: '>= 6'} + dependencies: + '@types/istanbul-lib-coverage': 2.0.6 + '@types/istanbul-reports': 1.1.2 + '@types/yargs': 13.0.12 + dev: false + /@jest/types@27.5.1: resolution: {integrity: sha512-Cx46iJ9QpwQTjIdq5VJu2QTMMs3QlEjI0x1QbBP5W1+nMzyc2XmimiRR/CbX9TO0cPTeUlxWMOu8mslYsJ8DEw==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} @@ -16446,13 +16459,20 @@ packages: /@types/istanbul-lib-report@3.0.0: resolution: {integrity: sha512-plGgXAPfVKFoYfa9NpYDAkseG+g6Jr294RqeqcqDixSbU34MZVJRi/P+7Y8GDpzkEwLaGZZOpKIEmeVZNtKsrg==} dependencies: - '@types/istanbul-lib-coverage': 2.0.4 + '@types/istanbul-lib-coverage': 2.0.6 /@types/istanbul-lib-report@3.0.3: resolution: {integrity: sha512-NQn7AHQnk/RSLOxrBbGyJM/aVQ+pjj5HCgasFxc0K/KhoATfQ/47AyUl15I2yBUpihjmas+a+VJBOqecrFH+uA==} dependencies: '@types/istanbul-lib-coverage': 2.0.6 + /@types/istanbul-reports@1.1.2: + resolution: {integrity: sha512-P/W9yOX/3oPZSpaYOCQzGqgCQRXn0FFO/V8bWrCQs+wLmvVVxk6CRBXALEvNs9OHIatlnlFokfhuDo2ug01ciw==} + dependencies: + '@types/istanbul-lib-coverage': 2.0.6 + '@types/istanbul-lib-report': 3.0.3 + dev: false + /@types/istanbul-reports@3.0.1: resolution: {integrity: sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==} dependencies: @@ -16891,6 +16911,12 @@ packages: /@types/yargs-parser@21.0.3: resolution: {integrity: sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==} + /@types/yargs@13.0.12: + resolution: {integrity: sha512-qCxJE1qgz2y0hA4pIxjBR+PelCH0U5CK1XJXFwCNqfmliatKp47UCXXE9Dyk1OXBDLvsCF57TqQEJaeLfDYEOQ==} + dependencies: + '@types/yargs-parser': 21.0.0 + dev: false + /@types/yargs@16.0.9: resolution: {integrity: sha512-tHhzvkFXZQeTECenFoRljLBYPZJ7jAVxqqtEI0qTLOmuultnFp4I9yKE17vTuhf7BkhCu7I4XuemPgikDVuYqA==} dependencies: @@ -19074,6 +19100,9 @@ packages: /ajv-formats@2.1.1: resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==} + peerDependenciesMeta: + ajv: + optional: true dependencies: ajv: 8.11.0 @@ -19177,7 +19206,6 @@ packages: /ansi-regex@4.1.1: resolution: {integrity: sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==} engines: {node: '>=6'} - dev: true /ansi-regex@5.0.1: resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} @@ -20624,6 +20652,18 @@ packages: - supports-color dev: true + /babel-plugin-react-compiler@0.0.0-experimental-c23de8d-20240515: + resolution: {integrity: sha512-0XN2gmpT55QtAz5n7d5g91y1AuO9tRhWBaLgCRyc4ExHrlr7+LfxW+YTb3mOwxngkkiggwM8HyYsaEK9MqhnlQ==} + dependencies: + '@babel/generator': 7.2.0 + '@babel/types': 7.23.6 + chalk: 4.1.2 + invariant: 2.2.4 + pretty-format: 24.9.0 + zod: 3.23.8 + zod-validation-error: 2.1.0(zod@3.23.8) + dev: false + /babel-plugin-react-require@3.0.0: resolution: {integrity: sha512-mZV3ycvtB4mfVhmScbU4CjMfBgoQAlsGu/vQw292juPSgvezTmBAke+V85ODAVNCM68r2Qa6dwu72Zcl4cTIbw==} dev: true @@ -36305,6 +36345,16 @@ packages: lodash: 4.17.21 renderkid: 3.0.0 + /pretty-format@24.9.0: + resolution: {integrity: sha512-00ZMZUiHaJrNfk33guavqgvfJS30sLYf0f8+Srklv0AMPodGGHcoHgksZ3OThYnIvOd+8yMCn0YiEOogjlgsnA==} + engines: {node: '>= 6'} + dependencies: + '@jest/types': 24.9.0 + ansi-regex: 4.1.1 + ansi-styles: 3.2.1 + react-is: 16.13.1 + dev: false + /pretty-format@27.5.1: resolution: {integrity: sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} @@ -44689,6 +44739,9 @@ packages: resolution: {integrity: sha512-AhwtHCKMtR71JgeYDaswmZXhPcW9iuI9Sp2LvZPo9upDZ7231ZJ7eA9RaURbhpXGVlrjX4cFNlB4ieTetEb7hQ==} engines: {node: '>=12.13.0'} hasBin: true + peerDependenciesMeta: + postcss: + optional: true dependencies: arg: 5.0.2 chokidar: 3.5.3 @@ -45252,6 +45305,11 @@ packages: escape-string-regexp: 1.0.5 dev: true + /trim-right@1.0.1: + resolution: {integrity: sha512-WZGXGstmCWgeevgTL54hrCuw1dyMQIzWy7ZfqRJfSmJZBwklI15egmQytFP6bPidmw3M8d5yEowl1niq4vmqZw==} + engines: {node: '>=0.10.0'} + dev: false + /triple-beam@1.3.0: resolution: {integrity: sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==} dev: true @@ -47688,10 +47746,23 @@ packages: commander: 2.20.3 dev: true + /zod-validation-error@2.1.0(zod@3.23.8): + resolution: {integrity: sha512-VJh93e2wb4c3tWtGgTa0OF/dTt/zoPCPzXq4V11ZjxmEAFaPi/Zss1xIZdEB5RD8GD00U0/iVXgqkF77RV7pdQ==} + engines: {node: '>=18.0.0'} + peerDependencies: + zod: ^3.18.0 + dependencies: + zod: 3.23.8 + dev: false + /zod@3.20.6: resolution: {integrity: sha512-oyu0m54SGCtzh6EClBVqDDlAYRz4jrVtKwQ7ZnsEmMI9HnzuZFj8QFwAY1M5uniIYACdGvv0PBWPF2kO0aNofA==} dev: true + /zod@3.23.8: + resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==} + dev: false + /zscroller@0.4.8: resolution: {integrity: sha512-G5NiNLKx2+QhhvZi2yV1jjVXY50otktxkseX2hG2N/eixohOUk0AY8ZpbAxNqS9oJS/NxItCsowupy2tsXxAMw==} dependencies: