Skip to content

🎥 Make videos programmatically with React

using env var is better

Igor Samokhovets8b497414178a
diff --git a/packages/docs/docs/electron.mdx b/packages/docs/docs/electron.mdx
index 138bdf3677..74f477aeb1 100644
--- a/packages/docs/docs/electron.mdx
+++ b/packages/docs/docs/electron.mdx
@@ -59,7 +59,7 @@ If rendering is behind a login wall, a purchase step, or another user action, yo
If you want to avoid a first-use download in packaged builds, you can also treat the browser as a packaged asset. Call [`ensureBrowser()`](/docs/renderer/ensure-browser) during packaging, copy the downloaded browser into `app.asar.unpacked`, and pass its path through the `browserExecutable` option in your packaged renders.
-The official [Electron template](/templates/electron) leaves this disabled by default. Uncomment the browser staging block in `forge.config.ts` if you want packaged renders to work completely offline. This will increase the final app size significantly.
+The official [Electron template](/templates/electron) leaves this disabled by default. Set `REMOTION_ELECTRON_PACKAGE_BROWSER=true` during packaging if you want packaged renders to work completely offline. This will increase the final app size significantly.
This is not supported for macOS universal builds. [`ensureBrowser()`](/docs/renderer/ensure-browser) only downloads a browser for the current architecture, so the other packaged architecture would not get an offline browser. For universal builds, prefer calling [`ensureBrowser()`](/docs/renderer/ensure-browser) at runtime instead.
diff --git a/packages/it-tests/src/templates/electron.test.ts b/packages/it-tests/src/templates/electron.test.ts
index a5b00577a9..0c094aff0a 100644
--- a/packages/it-tests/src/templates/electron.test.ts
+++ b/packages/it-tests/src/templates/electron.test.ts
@@ -85,33 +85,6 @@ async function copyTemplateForPublishCheck(workingDir: string): Promise<void> {
packageJsonPath,
contents.replaceAll('workspace:*', `^${remotionVersion}`),
);
-
- const forgeConfigPath = path.join(workingDir, 'forge.config.ts');
- const forgeConfig = readFileSync(forgeConfigPath, 'utf8');
- writeFileSync(
- forgeConfigPath,
- forgeConfig
- .replace(
- '// unpackDir: "{node_modules/@remotion/compositor-*,remotion-browser}",',
- 'unpackDir: "{node_modules/@remotion/compositor-*,remotion-browser}",',
- )
- .replace(
- 'unpackDir: "node_modules/@remotion/compositor-*",',
- '// unpackDir: "node_modules/@remotion/compositor-*",',
- )
- .replace(
- `// await stageBrowser({
- // arch,
- // buildPath,
- // platform,
- // });`,
- `await stageBrowser({
- arch,
- buildPath,
- platform,
- });`,
- ),
- );
}
async function packagePublishedTemplate(workingDir: string): Promise<void> {
@@ -123,6 +96,10 @@ async function packagePublishedTemplate(workingDir: string): Promise<void> {
await execa('bun', ['run', 'package'], {
cwd: workingDir,
stdio: 'inherit',
+ env: {
+ ...process.env,
+ REMOTION_ELECTRON_PACKAGE_BROWSER: 'true',
+ },
});
}
diff --git a/packages/template-electron/forge.config.ts b/packages/template-electron/forge.config.ts
index 2b2db01b0b..91aac468fd 100644
--- a/packages/template-electron/forge.config.ts
+++ b/packages/template-electron/forge.config.ts
@@ -11,8 +11,10 @@ const DARWIN_COMPOSITOR_PACKAGES = [
"@remotion/compositor-darwin-x64",
"@remotion/compositor-darwin-arm64",
];
+const PACKAGE_BROWSER_ENV_VAR = "REMOTION_ELECTRON_PACKAGE_BROWSER";
+const shouldPackageBrowser = process.env[PACKAGE_BROWSER_ENV_VAR] === "true";
-const DARWIN_UNIVERSAL_X64_ARCH_FILES =
+const DARWIN_UNIVERSAL_ARCH_FILES =
"Contents/Resources/app.asar.unpacked/node_modules/@remotion/compositor-darwin-*/**";
function getCompositorPackagesForPackaging({
@@ -155,16 +157,14 @@ export async function stageBrowser({
const config = {
packagerConfig: {
asar: {
- // Uncomment the line below if you also uncomment the browser staging block.
- // This will increase the final app size significantly, but packaged renders
- // can run completely offline.
- // unpackDir: "{node_modules/@remotion/compositor-*,remotion-browser}",
- unpackDir: "node_modules/@remotion/compositor-*",
+ unpackDir: shouldPackageBrowser
+ ? "{node_modules/@remotion/compositor-*,remotion-browser}"
+ : "node_modules/@remotion/compositor-*",
},
osxUniversal: {
// These compositor binaries are already architecture-specific and should not be
// merged with lipo during universal packaging.
- x64ArchFiles: DARWIN_UNIVERSAL_X64_ARCH_FILES,
+ x64ArchFiles: DARWIN_UNIVERSAL_ARCH_FILES,
},
},
rebuildConfig: {},
@@ -181,18 +181,20 @@ const config = {
outDir: getPrebuiltRemotionBundlePath(buildPath),
});
- // Uncomment to package Chrome Headless Shell into the app.
- // This will increase the final app size significantly, but packaged renders
- // can run completely offline.
- // IMPORTANT: This is not supported for macOS universal builds. `ensureBrowser()` only
- // downloads a browser for the current architecture, so the other packaged
- // architecture would not get an offline browser. For universal builds,
- // prefer calling `ensureBrowser()` at runtime instead.
- // await stageBrowser({
- // arch,
- // buildPath,
- // platform,
- // });
+ // Set REMOTION_ELECTRON_PACKAGE_BROWSER=true to package Chrome Headless
+ // Shell into the app. This increases the final app size significantly, but
+ // packaged renders can run completely offline.
+ // IMPORTANT: This is not supported for macOS universal builds.
+ // `ensureBrowser()` only downloads a browser for the current architecture,
+ // so the other packaged architecture would not get an offline browser.
+ // For universal builds, prefer calling `ensureBrowser()` at runtime instead.
+ if (shouldPackageBrowser) {
+ await stageBrowser({
+ arch,
+ buildPath,
+ platform,
+ });
+ }
// Electron Forge's Vite packaging does not materialize this optional runtime binary
// into the packaged app automatically, so stage the required compositor packages explicitly.