diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 41b0685098fa0..4f7d26cddbec9 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -149,7 +149,8 @@ function getBabelConfig( bundleType, packageName, externals, - isDevelopment + isDevelopment, + bundle ) { const canAccessReactObject = packageName === 'react' || externals.indexOf('react') !== -1; @@ -179,12 +180,6 @@ function getBabelConfig( case FB_WWW_DEV: case FB_WWW_PROD: case FB_WWW_PROFILING: - return Object.assign({}, options, { - plugins: options.plugins.concat([ - // Minify invariant messages - require('../error-codes/transform-error-messages'), - ]), - }); case RN_OSS_DEV: case RN_OSS_PROD: case RN_OSS_PROFILING: @@ -195,8 +190,9 @@ function getBabelConfig( plugins: options.plugins.concat([ [ require('../error-codes/transform-error-messages'), - // Preserve full error messages in React Native build - {noMinify: true}, + // Controls whether to replace error messages with error codes + // in production. By default, error messages are replaced. + {noMinify: bundle.minifyWithProdErrorCodes === false}, ], ]), }); @@ -390,7 +386,8 @@ function getPlugins( bundleType, packageName, externals, - !isProduction + !isProduction, + bundle ) ), // Remove 'use strict' from individual source files. diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index b9ae507b1a305..c24281d43ef08 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -79,6 +79,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react', global: 'React', + minifyWithProdErrorCodes: false, externals: ['ReactNativeInternalFeatureFlags'], }, @@ -88,6 +89,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react/unstable-shared-subset', global: 'React', + minifyWithProdErrorCodes: true, externals: [], }, @@ -105,6 +107,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react/jsx-runtime', global: 'JSXRuntime', + minifyWithProdErrorCodes: true, externals: ['react', 'ReactNativeInternalFeatureFlags'], }, @@ -124,6 +127,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react/jsx-dev-runtime', global: 'JSXDEVRuntime', + minifyWithProdErrorCodes: false, externals: ['react', 'ReactNativeInternalFeatureFlags'], }, @@ -133,6 +137,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react-fetch/index.browser', global: 'ReactFetch', + minifyWithProdErrorCodes: true, externals: ['react'], }, @@ -142,6 +147,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react-fetch/index.node', global: 'ReactFetch', + minifyWithProdErrorCodes: false, externals: ['react', 'http', 'https'], }, @@ -151,6 +157,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react-fs/index.browser.server', global: 'ReactFilesystem', + minifyWithProdErrorCodes: true, externals: [], }, @@ -160,6 +167,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react-fs/index.node.server', global: 'ReactFilesystem', + minifyWithProdErrorCodes: false, externals: ['react', 'fs/promises', 'path'], }, @@ -169,6 +177,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react-pg/index.browser.server', global: 'ReactPostgres', + minifyWithProdErrorCodes: true, externals: [], }, @@ -178,6 +187,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react-pg/index.node.server', global: 'ReactPostgres', + minifyWithProdErrorCodes: false, externals: ['react', 'pg'], }, @@ -197,6 +207,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-dom', global: 'ReactDOM', + minifyWithProdErrorCodes: true, externals: ['react'], }, @@ -207,6 +218,7 @@ const bundles = [ entry: 'react-dom', global: 'ReactDOMForked', enableNewReconciler: true, + minifyWithProdErrorCodes: true, externals: ['react'], }, @@ -216,15 +228,18 @@ const bundles = [ bundleTypes: [FB_WWW_DEV, NODE_DEV, NODE_PROD, UMD_DEV, UMD_PROD], entry: 'react-dom/test-utils', global: 'ReactTestUtils', + minifyWithProdErrorCodes: false, externals: ['react', 'react-dom'], }, + // TODO: We don't use this bundle anymore /******* React DOM - www - Testing *******/ { moduleType: RENDERER, bundleTypes: [FB_WWW_DEV, FB_WWW_PROD], entry: 'react-dom/testing', global: 'ReactDOMTesting', + minifyWithProdErrorCodes: true, externals: ['react'], }, @@ -237,6 +252,7 @@ const bundles = [ entry: 'react-dom/src/server/ReactDOMLegacyServerBrowser', name: 'react-dom-server-legacy.browser', global: 'ReactDOMServer', + minifyWithProdErrorCodes: true, externals: ['react'], babel: opts => Object.assign({}, opts, { @@ -251,6 +267,7 @@ const bundles = [ entry: 'react-dom/src/server/ReactDOMLegacyServerNode', name: 'react-dom-server-legacy.node', externals: ['react', 'stream'], + minifyWithProdErrorCodes: false, babel: opts => Object.assign({}, opts, { plugins: opts.plugins.concat([ @@ -266,6 +283,7 @@ const bundles = [ entry: 'react-dom/src/server/ReactDOMFizzServerBrowser', name: 'react-dom-server.browser', global: 'ReactDOMServer', + minifyWithProdErrorCodes: true, externals: ['react'], }, { @@ -274,6 +292,7 @@ const bundles = [ entry: 'react-dom/src/server/ReactDOMFizzServerNode', name: 'react-dom-server.node', global: 'ReactDOMServer', + minifyWithProdErrorCodes: false, externals: ['react'], }, { @@ -281,6 +300,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-server-dom-relay/src/ReactDOMServerFB', global: 'ReactDOMServer', + minifyWithProdErrorCodes: false, externals: ['react'], }, @@ -290,6 +310,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-server-dom-webpack/writer.browser.server', global: 'ReactServerDOMWriter', + minifyWithProdErrorCodes: false, externals: ['react'], }, { @@ -297,6 +318,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-server-dom-webpack/writer.node.server', global: 'ReactServerDOMWriter', + minifyWithProdErrorCodes: false, externals: ['react'], }, @@ -306,6 +328,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-server-dom-webpack', global: 'ReactServerDOMReader', + minifyWithProdErrorCodes: true, externals: ['react'], }, @@ -315,6 +338,7 @@ const bundles = [ moduleType: RENDERER_UTILS, entry: 'react-server-dom-webpack/plugin', global: 'ReactServerWebpackPlugin', + minifyWithProdErrorCodes: false, externals: ['fs', 'path', 'url', 'neo-async'], }, @@ -324,6 +348,7 @@ const bundles = [ moduleType: RENDERER_UTILS, entry: 'react-server-dom-webpack/node-loader', global: 'ReactServerWebpackNodeLoader', + minifyWithProdErrorCodes: false, externals: ['acorn'], }, @@ -333,6 +358,7 @@ const bundles = [ moduleType: RENDERER_UTILS, entry: 'react-server-dom-webpack/node-register', global: 'ReactFlightWebpackNodeRegister', + minifyWithProdErrorCodes: false, externals: ['url', 'module'], }, @@ -342,6 +368,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-server-dom-relay/server', global: 'ReactFlightDOMRelayServer', // TODO: Rename to Writer + minifyWithProdErrorCodes: false, externals: [ 'react', 'ReactFlightDOMRelayServerIntegration', @@ -355,6 +382,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-server-dom-relay', global: 'ReactFlightDOMRelayClient', // TODO: Rename to Reader + minifyWithProdErrorCodes: true, externals: [ 'react', 'ReactFlightDOMRelayClientIntegration', @@ -368,6 +396,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-server-native-relay/server', global: 'ReactFlightNativeRelayServer', // TODO: Rename to Writer + minifyWithProdErrorCodes: false, externals: [ 'react', 'ReactFlightNativeRelayServerIntegration', @@ -382,6 +411,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-server-native-relay', global: 'ReactFlightNativeRelayClient', // TODO: Rename to Reader + minifyWithProdErrorCodes: true, externals: [ 'react', 'ReactFlightNativeRelayClientIntegration', @@ -396,6 +426,7 @@ const bundles = [ moduleType: RENDERER_UTILS, entry: 'react-suspense-test-utils', global: 'ReactSuspenseTestUtils', + minifyWithProdErrorCodes: false, externals: ['react'], }, @@ -413,6 +444,7 @@ const bundles = [ entry: 'react-art', global: 'ReactART', externals: ['react'], + minifyWithProdErrorCodes: true, babel: opts => Object.assign({}, opts, { // Include JSX @@ -435,6 +467,7 @@ const bundles = [ entry: 'react-native-renderer', global: 'ReactNativeRenderer', externals: ['react-native', 'ReactNativeInternalFeatureFlags'], + minifyWithProdErrorCodes: false, babel: opts => Object.assign({}, opts, { plugins: opts.plugins.concat([ @@ -448,6 +481,7 @@ const bundles = [ entry: 'react-native-renderer', global: 'ReactNativeRenderer', externals: ['react-native'], + minifyWithProdErrorCodes: false, babel: opts => Object.assign({}, opts, { plugins: opts.plugins.concat([ @@ -465,6 +499,7 @@ const bundles = [ entry: 'react-native-renderer/fabric', global: 'ReactFabric', externals: ['react-native', 'ReactNativeInternalFeatureFlags'], + minifyWithProdErrorCodes: false, babel: opts => Object.assign({}, opts, { plugins: opts.plugins.concat([ @@ -478,6 +513,7 @@ const bundles = [ entry: 'react-native-renderer/fabric', global: 'ReactFabric', externals: ['react-native'], + minifyWithProdErrorCodes: false, babel: opts => Object.assign({}, opts, { plugins: opts.plugins.concat([ @@ -507,6 +543,7 @@ const bundles = [ 'scheduler/unstable_mock', 'ReactNativeInternalFeatureFlags', ], + minifyWithProdErrorCodes: false, babel: opts => Object.assign({}, opts, { plugins: opts.plugins.concat([ @@ -521,6 +558,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-noop-renderer', global: 'ReactNoopRenderer', + minifyWithProdErrorCodes: true, externals: ['react', 'scheduler', 'scheduler/unstable_mock', 'expect'], }, @@ -530,6 +568,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-noop-renderer/persistent', global: 'ReactNoopRendererPersistent', + minifyWithProdErrorCodes: true, externals: ['react', 'scheduler', 'expect'], }, @@ -539,6 +578,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-noop-renderer/server', global: 'ReactNoopRendererServer', + minifyWithProdErrorCodes: true, externals: ['react', 'scheduler', 'expect'], }, @@ -548,6 +588,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-noop-renderer/flight-server', global: 'ReactNoopFlightServer', + minifyWithProdErrorCodes: false, externals: [ 'react', 'scheduler', @@ -562,6 +603,7 @@ const bundles = [ moduleType: RENDERER, entry: 'react-noop-renderer/flight-client', global: 'ReactNoopFlightClient', + minifyWithProdErrorCodes: false, externals: [ 'react', 'scheduler', @@ -576,6 +618,7 @@ const bundles = [ moduleType: RECONCILER, entry: 'react-reconciler', global: 'ReactReconciler', + minifyWithProdErrorCodes: true, externals: ['react'], }, @@ -585,6 +628,7 @@ const bundles = [ moduleType: RECONCILER, entry: 'react-server', global: 'ReactServer', + minifyWithProdErrorCodes: false, externals: ['react'], }, @@ -594,6 +638,7 @@ const bundles = [ moduleType: RECONCILER, entry: 'react-server/flight', global: 'ReactFlightServer', + minifyWithProdErrorCodes: false, externals: ['react'], }, @@ -603,6 +648,7 @@ const bundles = [ moduleType: RECONCILER, entry: 'react-client/flight', global: 'ReactFlightClient', + minifyWithProdErrorCodes: true, externals: ['react'], }, @@ -612,6 +658,7 @@ const bundles = [ bundleTypes: [NODE_DEV, NODE_PROD], entry: 'react-reconciler/reflection', global: 'ReactFiberTreeReflection', + minifyWithProdErrorCodes: true, externals: [], }, @@ -621,6 +668,7 @@ const bundles = [ bundleTypes: [NODE_DEV, NODE_PROD], entry: 'react-reconciler/constants', global: 'ReactReconcilerConstants', + minifyWithProdErrorCodes: true, externals: [], }, @@ -637,6 +685,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react-is', global: 'ReactIs', + minifyWithProdErrorCodes: true, externals: [], }, @@ -646,6 +695,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react-debug-tools', global: 'ReactDebugTools', + minifyWithProdErrorCodes: false, externals: [], }, @@ -657,6 +707,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react-cache', global: 'ReactCacheOld', + minifyWithProdErrorCodes: false, externals: ['react', 'scheduler'], }, @@ -667,6 +718,7 @@ const bundles = [ entry: 'create-subscription', global: 'createSubscription', externals: ['react'], + minifyWithProdErrorCodes: true, babel: opts => Object.assign({}, opts, { plugins: opts.plugins.concat([ @@ -681,6 +733,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'use-subscription', global: 'useSubscription', + minifyWithProdErrorCodes: true, externals: ['react'], }, @@ -690,6 +743,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'use-sync-external-store', global: 'useSyncExternalStore', + minifyWithProdErrorCodes: true, externals: ['react'], }, @@ -699,6 +753,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'use-sync-external-store/extra', global: 'useSyncExternalStoreExtra', + minifyWithProdErrorCodes: true, externals: ['react', 'use-sync-external-store'], }, @@ -708,6 +763,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'use-sync-external-store/index.native', global: 'useSyncExternalStoreNative', + minifyWithProdErrorCodes: true, externals: ['react', 'ReactNativeInternalFeatureFlags'], }, @@ -726,6 +782,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'scheduler', global: 'Scheduler', + minifyWithProdErrorCodes: true, externals: ['ReactNativeInternalFeatureFlags'], }, @@ -744,6 +801,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'scheduler/unstable_mock', global: 'SchedulerMock', + minifyWithProdErrorCodes: false, externals: ['ReactNativeInternalFeatureFlags'], }, @@ -759,6 +817,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'scheduler/unstable_post_task', global: 'SchedulerPostTask', + minifyWithProdErrorCodes: true, externals: [], }, @@ -768,6 +827,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'jest-react', global: 'JestReact', + minifyWithProdErrorCodes: false, externals: ['react', 'scheduler', 'scheduler/unstable_mock'], }, @@ -781,6 +841,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'eslint-plugin-react-hooks', global: 'ESLintPluginReactHooks', + minifyWithProdErrorCodes: false, externals: [], }, @@ -790,6 +851,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react-refresh/babel', global: 'ReactFreshBabelPlugin', + minifyWithProdErrorCodes: false, externals: [], }, { @@ -797,6 +859,7 @@ const bundles = [ moduleType: ISOMORPHIC, entry: 'react-refresh/runtime', global: 'ReactFreshRuntime', + minifyWithProdErrorCodes: false, externals: [], }, ];