Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions bin/packages/build-vendors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const VENDOR_SCRIPTS = [
global: 'ReactDOM',
handle: 'react-dom',
dependencies: [ 'react' ],
contents: [
'export * from "react-dom";',
'export { createRoot, hydrateRoot } from "react-dom/client";',
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The react-dom/client re-exports will reliably override the * re-export from react-dom, we don't need to do any special tricks here.

].join( '\n' ),
},
{
name: 'react/jsx-runtime',
Expand Down Expand Up @@ -87,7 +91,7 @@ async function generateAssetFile( config ) {
* @return {Promise<void>} Promise that resolves when all builds are finished.
*/
async function bundleVendorScript( config ) {
const { name, global, handle } = config;
const { name, global, handle, contents } = config;

// Plugin that externalizes the `react` package.
const reactExternalPlugin = {
Expand All @@ -114,7 +118,6 @@ async function bundleVendorScript( config ) {
};

const esbuildOptions = {
entryPoints: [ name ],
bundle: true,
format: 'iife',
globalName: global,
Expand All @@ -123,6 +126,16 @@ async function bundleVendorScript( config ) {
plugins: [ reactExternalPlugin ],
};

if ( contents ) {
esbuildOptions.stdin = {
contents,
resolveDir: ROOT_DIR,
loader: 'js',
};
} else {
esbuildOptions.entryPoints = [ name ];
}

await Promise.all( [
esbuild.build( {
...esbuildOptions,
Expand Down Expand Up @@ -150,11 +163,11 @@ async function buildVendors() {
await bundleVendorScript( vendorConfig );
const buildTime = Date.now() - startTime;
console.log(
` ✔ Bundled vendor ${ vendorConfig.name } (${ buildTime }ms)`
` ✔ Bundled vendor ${ vendorConfig.handle } (${ buildTime }ms)`
);
} catch ( error ) {
console.error(
` ✘ Failed to bundle vendor ${ vendorConfig.name }: ${ error.message }`
` ✘ Failed to bundle vendor ${ vendorConfig.handle }: ${ error.message }`
);
}
}
Expand Down
Loading