Skip to content

🎥 Make videos programmatically with React

Keep Studio ESM entry points in a shared bundle

JonnyBurgeref2898b049e7
diff --git a/packages/.monorepo/builder.ts b/packages/.monorepo/builder.ts
index 5571fe8730..32a9b627e0 100644
--- a/packages/.monorepo/builder.ts
+++ b/packages/.monorepo/builder.ts
@@ -70,7 +70,7 @@ const sortObject = (obj: Record<string, string>) => {
};
};
-type FormatAction = 'do-nothing' | 'build' | 'use-tsc';
+type FormatAction = 'do-nothing' | 'build' | 'build-shared' | 'use-tsc';
type EntryPoint = {
target: 'node' | 'browser';
@@ -111,17 +111,29 @@ export const buildPackage = async ({
if (action === 'do-nothing') {
continue;
} else if (action === 'use-tsc') {
- } else if (action === 'build') {
- for (const {path: p, target, splitting} of entrypoints) {
+ } else if (action === 'build' || action === 'build-shared') {
+ if (
+ action === 'build-shared' &&
+ entrypoints.some(({target}) => target !== entrypoints[0].target)
+ ) {
+ throw new Error('Shared entry points must use the same target');
+ }
+
+ const batches =
+ action === 'build-shared'
+ ? [entrypoints]
+ : entrypoints.map((entrypoint) => [entrypoint]);
+ for (const batch of batches) {
+ const {target, splitting} = batch[0];
const externalFinal = filterExternal(getExternal(external));
validateExternal(externalFinal);
const output = await build({
- entrypoints: [p],
+ entrypoints: batch.map(({path: entryPath}) => entryPath),
naming: `[name].${format === 'esm' ? 'mjs' : 'js'}`,
external: externalFinal,
target,
format,
- splitting: splitting ?? false,
+ splitting: action === 'build-shared' || (splitting ?? false),
});
for (const file of output.outputs) {
diff --git a/packages/studio/bundle.ts b/packages/studio/bundle.ts
index 4d4b10fad8..3c630d2c3e 100644
--- a/packages/studio/bundle.ts
+++ b/packages/studio/bundle.ts
@@ -25,7 +25,8 @@ const external = [
await buildPackage({
formats: {
- esm: 'build',
+ // Keep visual controls and other singleton state shared across entry points.
+ esm: 'build-shared',
cjs: 'use-tsc',
},
external,