🎥 Make videos programmatically with React
webpack is aware of remotion root
Jonny Burgerb9a7b5f8d6e3
diff --git a/packages/bundler/src/bundle.ts b/packages/bundler/src/bundle.tsindex 6af92aa413..f02269b91d 100644--- a/packages/bundler/src/bundle.ts+++ b/packages/bundler/src/bundle.ts@@ -37,19 +37,27 @@ const trimTrailingSlash = (p: string): string => {return p;};-type Options = {+export type BundleOptions = {webpackOverride?: WebpackOverrideFn;outDir?: string;enableCaching?: boolean;publicPath?: string;+ remotionRoot?: string;};-export const getConfig = (- outDir: string,- entryPoint: string,- onProgressUpdate?: (progress: number) => void,- options?: Options-) => {+export const getConfig = ({+ entryPoint,+ outDir,+ resolvedRemotionRoot,+ onProgressUpdate,+ options,+}: {+ outDir: string;+ entryPoint: string;+ resolvedRemotionRoot: string;+ onProgressUpdate?: (progress: number) => void;+ options?: BundleOptions;+}) => {return webpackConfig({entry,userDefinedComponent: entryPoint,@@ -62,17 +70,25 @@ export const getConfig = (// For production, the variables are set dynamicallyenvVariables: {},entryPoints: [],+ remotionRoot: resolvedRemotionRoot,});};export const bundle = async (entryPoint: string,onProgressUpdate?: (progress: number) => void,- options?: Options+ options?: BundleOptions): Promise<string> => {+ const resolvedRemotionRoot = options?.remotionRoot ?? process.cwd();const outDir = await prepareOutDir(options?.outDir ?? null);- const [, config] = getConfig(outDir, entryPoint, onProgressUpdate, options);+ const [, config] = getConfig({+ outDir,+ entryPoint,+ resolvedRemotionRoot,+ onProgressUpdate,+ options,+ });const output = await promisified([config]);if (!output) {@@ -91,7 +107,8 @@ export const bundle = async (.filter(Boolean).join('/');- const from = path.join(process.cwd(), 'public');+ // TODO: Unhardcode public directory+ const from = path.join(resolvedRemotionRoot, 'public');const to = path.join(outDir, 'public');if (fs.existsSync(from)) {await copyDir(from, to);diff --git a/packages/bundler/src/index.ts b/packages/bundler/src/index.tsindex 606e085bdb..dec24fe282 100644--- a/packages/bundler/src/index.ts+++ b/packages/bundler/src/index.ts@@ -14,7 +14,7 @@ export const BundlerInternals = {getConfig,};-export {bundle} from './bundle';+export {bundle, BundleOptions} from './bundle';export {webpack};export type WebpackConfiguration = webpack.Configuration;diff --git a/packages/bundler/src/webpack-config.ts b/packages/bundler/src/webpack-config.tsindex 7fa01ded1d..28b8f7beac 100644--- a/packages/bundler/src/webpack-config.ts+++ b/packages/bundler/src/webpack-config.ts@@ -44,6 +44,7 @@ export const webpackConfig = ({envVariables,maxTimelineTracks,entryPoints,+ remotionRoot,}: {entry: string;userDefinedComponent: string;@@ -55,6 +56,7 @@ export const webpackConfig = ({envVariables: Record<string, string>;maxTimelineTracks: number;entryPoints: string[];+ remotionRoot: string;}): [string, WebpackConfiguration] => {const conf: webpack.Configuration = webpackOverride({optimization: {@@ -194,6 +196,7 @@ export const webpackConfig = ({...conf.output,path: outDir,},+ context: remotionRoot,},];};diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.tsindex 021f9bb43a..b5ce441652 100644--- a/packages/cli/src/compositions.ts+++ b/packages/cli/src/compositions.ts@@ -54,7 +54,11 @@ export const listCompositionsCommand = async (remotionRoot: string) => {type: 'get-compositions',});- const bundled = await bundleOnCli({fullPath, steps: ['bundling']});+ const bundled = await bundleOnCli({+ remotionRoot,+ fullPath,+ steps: ['bundling'],+ });const compositions = await getCompositions(bundled, {browserExecutable,diff --git a/packages/cli/src/preview-server/start-server.ts b/packages/cli/src/preview-server/start-server.tsindex a9087f2665..b4ea78d342 100644--- a/packages/cli/src/preview-server/start-server.ts+++ b/packages/cli/src/preview-server/start-server.ts@@ -46,6 +46,7 @@ export const startServer = async (require.resolve('./hot-middleware/client'),require.resolve('./error-overlay/entry-basic.js'),],+ remotionRoot: options.remotionRoot,});const compiler = webpack(config);diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 66b407dba3..d8270bbaeb 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -121,7 +121,7 @@ export const render = async (remotionRoot: string) => {const urlOrBundle = RenderInternals.isServeUrl(fullPath)? fullPath- : await bundleOnCli({fullPath, steps});+ : await bundleOnCli({fullPath, remotionRoot, steps});const onDownload: RenderMediaOnDownload = (src) => {const id = Math.random();diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.tsindex 194f9f9e34..c9a10a98e1 100644--- a/packages/cli/src/setup-cache.ts+++ b/packages/cli/src/setup-cache.ts@@ -1,3 +1,4 @@+import type {BundleOptions} from '@remotion/bundler';import {bundle, BundlerInternals} from '@remotion/bundler';import {ConfigInternals} from './config';import {Log} from './log';@@ -11,9 +12,11 @@ import type {RenderStep} from './step';export const bundleOnCli = async ({fullPath,steps,+ remotionRoot,}: {fullPath: string;steps: RenderStep[];+ remotionRoot: string;}) => {const shouldCache = ConfigInternals.getWebpackCaching();@@ -27,12 +30,18 @@ export const bundleOnCli = async ({);};- const options = {+ const options: BundleOptions = {enableCaching: shouldCache,webpackOverride: ConfigInternals.getWebpackOverrideFn() ?? ((f) => f),};- const [hash] = BundlerInternals.getConfig('', fullPath, onProgress, options);+ const [hash] = BundlerInternals.getConfig({+ outDir: '',+ entryPoint: fullPath,+ onProgressUpdate: onProgress,+ options,+ resolvedRemotionRoot: remotionRoot,+ });const cacheExistedBefore = BundlerInternals.cacheExists('production', hash);if (cacheExistedBefore !== 'does-not-exist' && !shouldCache) {diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.tsindex 52e893270d..5dbb907c9a 100644--- a/packages/cli/src/still.ts+++ b/packages/cli/src/still.ts@@ -141,7 +141,7 @@ export const still = async (remotionRoot: string) => {const urlOrBundle = RenderInternals.isServeUrl(fullPath)? Promise.resolve(fullPath)- : await bundleOnCli({fullPath, steps});+ : await bundleOnCli({fullPath, remotionRoot, steps});const puppeteerInstance = await browserInstance;const comps = await getCompositions(await urlOrBundle, {