diff --git a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-client.node.unbundled.development.js b/packages/react-server-dom-webpack/client.node.unbundled.js similarity index 79% rename from packages/react-server-dom-webpack/esm/react-server-dom-webpack-client.node.unbundled.development.js rename to packages/react-server-dom-webpack/client.node.unbundled.js index 9251e4c7ff194..4f435353a20f0 100644 --- a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-client.node.unbundled.development.js +++ b/packages/react-server-dom-webpack/client.node.unbundled.js @@ -7,4 +7,4 @@ * @flow */ -export * from '../src/ReactFlightDOMClientNode.js'; +export * from './src/ReactFlightDOMClientNode'; diff --git a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.development.js b/packages/react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.development.js deleted file mode 100644 index 1d40bdf58054e..0000000000000 --- a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.development.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow - */ - -export * from '../src/ReactFlightDOMServerNode.js'; diff --git a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.production.min.js b/packages/react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.production.min.js deleted file mode 100644 index 1d40bdf58054e..0000000000000 --- a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.production.min.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow - */ - -export * from '../src/ReactFlightDOMServerNode.js'; diff --git a/packages/react-server-dom-webpack/npm/client.node.unbundled.js b/packages/react-server-dom-webpack/npm/client.node.unbundled.js new file mode 100644 index 0000000000000..17fe876fd388a --- /dev/null +++ b/packages/react-server-dom-webpack/npm/client.node.unbundled.js @@ -0,0 +1,7 @@ +'use strict'; + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/react-server-dom-webpack-client.node.unbundled.production.min.js'); +} else { + module.exports = require('./cjs/react-server-dom-webpack-client.node.unbundled.development.js'); +} diff --git a/packages/react-server-dom-webpack/npm/server.node.unbundled.js b/packages/react-server-dom-webpack/npm/server.node.unbundled.js new file mode 100644 index 0000000000000..5f75de80942a2 --- /dev/null +++ b/packages/react-server-dom-webpack/npm/server.node.unbundled.js @@ -0,0 +1,7 @@ +'use strict'; + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/react-server-dom-webpack-server.node.unbundled.production.min.js'); +} else { + module.exports = require('./cjs/react-server-dom-webpack-server.node.unbundled.development.js'); +} diff --git a/packages/react-server-dom-webpack/package.json b/packages/react-server-dom-webpack/package.json index e2764a7eccf0e..3f09719bb06e7 100644 --- a/packages/react-server-dom-webpack/package.json +++ b/packages/react-server-dom-webpack/package.json @@ -38,8 +38,7 @@ "worker": "./client.edge.js", "node": { "webpack": "./client.node.js", - "production": "./esm/react-server-dom-webpack-client.node.unbundled.production.min.js", - "default": "./esm/react-server-dom-webpack-client.node.unbundled.development.js" + "default": "./client.node.unbundled.js" }, "browser": "./client.browser.js", "default": "./client.browser.js" @@ -47,10 +46,7 @@ "./client.browser": "./client.browser.js", "./client.edge": "./client.edge.js", "./client.node": "./client.node.js", - "./client.node.unbundled": { - "production": "./esm/react-server-dom-webpack-client.node.unbundled.production.min.js", - "default": "./esm/react-server-dom-webpack-client.node.unbundled.development.js" - }, + "./client.node.unbundled": "./client.node.unbundled.js", "./server": { "react-server": { "workerd": "./server.edge.js", @@ -58,8 +54,7 @@ "deno": "./server.browser.js", "node": { "webpack": "./server.node.js", - "production": "./esm/react-server-dom-webpack-server.node.unbundled.production.min.js", - "default": "./esm/react-server-dom-webpack-server.node.unbundled.development.js" + "default": "./server.node.unbundled.js" }, "browser": "./server.browser.js" }, @@ -68,10 +63,7 @@ "./server.browser": "./server.browser.js", "./server.edge": "./server.edge.js", "./server.node": "./server.node.js", - "./server.node.unbundled": { - "production": "./esm/react-server-dom-webpack-server.node.unbundled.production.min.js", - "default": "./esm/react-server-dom-webpack-server.node.unbundled.development.js" - }, + "./server.node.unbundled": "./server.node.unbundled.js", "./node-loader": "./esm/react-server-dom-webpack-node-loader.production.min.js", "./node-register": "./node-register.js", "./src/*": "./src/*", diff --git a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-client.node.unbundled.production.min.js b/packages/react-server-dom-webpack/server.node.unbundled.js similarity index 79% rename from packages/react-server-dom-webpack/esm/react-server-dom-webpack-client.node.unbundled.production.min.js rename to packages/react-server-dom-webpack/server.node.unbundled.js index 9251e4c7ff194..7726b9bb929d4 100644 --- a/packages/react-server-dom-webpack/esm/react-server-dom-webpack-client.node.unbundled.production.min.js +++ b/packages/react-server-dom-webpack/server.node.unbundled.js @@ -7,4 +7,4 @@ * @flow */ -export * from '../src/ReactFlightDOMClientNode.js'; +export * from './src/ReactFlightDOMServerNode'; diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 4647772436045..ea02647da767d 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -19,6 +19,7 @@ const Sync = require('./sync'); const sizes = require('./plugins/sizes-plugin'); const useForks = require('./plugins/use-forks-plugin'); const stripUnusedImports = require('./plugins/strip-unused-imports'); +const dynamicImports = require('./plugins/dynamic-imports'); const Packaging = require('./packaging'); const {asyncRimRaf} = require('./utils'); const codeFrame = require('@babel/code-frame'); @@ -332,6 +333,8 @@ function getPlugins( bundleType === RN_FB_PROFILING; const shouldStayReadable = isFBWWWBundle || isRNBundle || forcePrettyOutput; return [ + // Keep dynamic imports as externals + dynamicImports(), { name: 'rollup-plugin-flow-remove-types', transform(code) { @@ -410,6 +413,7 @@ function getPlugins( process_common_js_modules: false, rewrite_polyfills: false, inject_libraries: false, + allow_dynamic_import: true, // Don't let it create global variables in the browser. // https://github.com/facebook/react/issues/10909 diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index 66fe7bc875039..e4ff1cf8bf0f7 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -360,7 +360,7 @@ const bundles = [ externals: ['react', 'util', 'async_hooks', 'react-dom'], }, { - bundleTypes: [ESM_DEV, ESM_PROD], + bundleTypes: [NODE_DEV, NODE_PROD], moduleType: RENDERER, entry: 'react-server-dom-webpack/server.node.unbundled', global: 'ReactServerDOMServer', @@ -398,7 +398,7 @@ const bundles = [ externals: ['react', 'util'], }, { - bundleTypes: [ESM_DEV, ESM_PROD], + bundleTypes: [NODE_DEV, NODE_PROD], moduleType: RENDERER, entry: 'react-server-dom-webpack/client.node.unbundled', global: 'ReactServerDOMClient', diff --git a/scripts/rollup/plugins/dynamic-imports.js b/scripts/rollup/plugins/dynamic-imports.js new file mode 100644 index 0000000000000..10bda3f05a4f1 --- /dev/null +++ b/scripts/rollup/plugins/dynamic-imports.js @@ -0,0 +1,19 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +'use strict'; + +module.exports = function dynamicImports() { + return { + name: 'scripts/rollup/plugins/dynamic-imports', + renderDynamicImport({targetModuleId}) { + if (targetModuleId === null) { + return {left: 'import(', right: ')'}; + } + return null; + }, + }; +}; diff --git a/scripts/rollup/validate/eslintrc.cjs.js b/scripts/rollup/validate/eslintrc.cjs.js index 67d3c06dfc84e..64d3ddc8aeef7 100644 --- a/scripts/rollup/validate/eslintrc.cjs.js +++ b/scripts/rollup/validate/eslintrc.cjs.js @@ -53,7 +53,7 @@ module.exports = { IS_REACT_ACT_ENVIRONMENT: 'readonly', }, parserOptions: { - ecmaVersion: 5, + ecmaVersion: 2020, sourceType: 'script', }, rules: { diff --git a/scripts/shared/inlinedHostConfigs.js b/scripts/shared/inlinedHostConfigs.js index 41227972e6ae8..cf65774ca8048 100644 --- a/scripts/shared/inlinedHostConfigs.js +++ b/scripts/shared/inlinedHostConfigs.js @@ -33,8 +33,6 @@ module.exports = [ 'react-server-dom-webpack/client.node.unbundled', 'react-server-dom-webpack/server', 'react-server-dom-webpack/server.node.unbundled', - 'react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.production.min.js', - 'react-server-dom-webpack/esm/react-server-dom-webpack-server.node.unbundled.development.js', 'react-server-dom-webpack/src/ReactFlightDOMServerNode.js', // react-server-dom-webpack/server.node 'react-client/src/ReactFlightClientStream.js', // We can only type check this in streaming configurations. 'react-devtools',