🎥 Make videos programmatically with React
handle variables in index html script tag
Antoine Caroncd0f87c54f4c
diff --git a/packages/bundler/src/index-html.ts b/packages/bundler/src/index-html.tsindex 0c36237bdf..0552458567 100644--- a/packages/bundler/src/index-html.ts+++ b/packages/bundler/src/index-html.ts@@ -4,6 +4,7 @@ export const indexHtml = ({baseDir,editorName,inputProps,+ envVariables,staticHash,remotionRoot,previewServerCommand,@@ -12,6 +13,7 @@ export const indexHtml = ({baseDir: string;editorName: string | null;inputProps: object | null;+ envVariables?: Record<string, string>remotionRoot: string;previewServerCommand: string | null;}) =>@@ -49,6 +51,14 @@ export const indexHtml = ({`: ''}+ ${+ envVariables+ ? `<script> window.process = {+ env: ${JSON.stringify(envVariables)}+ };</script>+ `+ : ''+ }<div id="container"></div><div id="menuportal-0"></div>diff --git a/packages/cli/src/get-env.ts b/packages/cli/src/get-env.tsindex 563543cbc8..7f5a54a6f6 100644--- a/packages/cli/src/get-env.ts+++ b/packages/cli/src/get-env.ts@@ -27,7 +27,6 @@ const getEnvForEnvFile = async () => {try {const envFileData = await fs.promises.readFile(envFile);-fs.watchFile(envFile, {interval: 100}, async () => {try {const file = await fs.promises.readFile(envFile, 'utf-8')diff --git a/packages/cli/src/preview-server/routes.ts b/packages/cli/src/preview-server/routes.tsindex 57e0f9dcf1..7e3da10d5b 100644--- a/packages/cli/src/preview-server/routes.ts+++ b/packages/cli/src/preview-server/routes.ts@@ -41,11 +41,13 @@ const handleFallback = async ({hash,response,getCurrentInputProps,+ getEnvVariables,}: {remotionRoot: string;hash: string;response: ServerResponse;getCurrentInputProps: () => object;+ getEnvVariables: () => Record<string, string>;}) => {const [edit] = await editorGuess;const displayName = getDisplayNameForEditor(edit ? edit.command : null);@@ -58,6 +60,7 @@ const handleFallback = async ({staticHash: hash,baseDir: '/',editorName: displayName,+ envVariables: getEnvVariables(),inputProps: getCurrentInputProps(),remotionRoot,previewServerCommand:@@ -184,6 +187,7 @@ export const handleRoutes = ({response,liveEventsServer,getCurrentInputProps,+ getEnvVariables,remotionRoot,userPassedPublicDir,}: {@@ -193,6 +197,7 @@ export const handleRoutes = ({response: ServerResponse;liveEventsServer: LiveEventsServer;getCurrentInputProps: () => object;+ getEnvVariables: () => Record<string, string>;remotionRoot: string;userPassedPublicDir: string | null;}) => {@@ -243,5 +248,6 @@ export const handleRoutes = ({hash,response,getCurrentInputProps,+ getEnvVariables,});};diff --git a/packages/cli/src/preview-server/start-server.ts b/packages/cli/src/preview-server/start-server.tsindex 9c0e7cba11..a75c74775d 100644--- a/packages/cli/src/preview-server/start-server.ts+++ b/packages/cli/src/preview-server/start-server.ts@@ -21,7 +21,7 @@ export const startServer = async (options: {webpackOverride: WebpackOverrideFn;getCurrentInputProps: () => object;- envVariables?: Record<string, string>;+ getEnvVariables: () => Record<string, string>;port: number | null;maxTimelineTracks?: number;remotionRoot: string;@@ -43,7 +43,7 @@ export const startServer = async (environment: 'development',webpackOverride:options?.webpackOverride ?? ConfigInternals.getWebpackOverrideFn(),- envVariables: options?.envVariables ?? {},+ envVariables: options?.getEnvVariables() ?? {},maxTimelineTracks: options?.maxTimelineTracks ?? 15,entryPoints: [require.resolve('./hot-middleware/client'),@@ -84,6 +84,7 @@ export const startServer = async (response,liveEventsServer,getCurrentInputProps: options.getCurrentInputProps,+ getEnvVariables: options.getEnvVariables,remotionRoot: options.remotionRoot,userPassedPublicDir: options.userPassedPublicDir,});diff --git a/packages/cli/src/preview.ts b/packages/cli/src/preview.tsindex d3fb35b645..f4bbf6e61c 100644--- a/packages/cli/src/preview.ts+++ b/packages/cli/src/preview.ts@@ -72,7 +72,7 @@ export const previewCommand = async (remotionRoot: string) => {fullPath,{getCurrentInputProps: () => inputProps,- envVariables,+ getEnvVariables: () => envVariables,port: desiredPort,maxTimelineTracks: ConfigInternals.getMaxTimelineTracks(),remotionRoot,