Skip to content

🎥 Make videos programmatically with React

implement publicDir

Jonny Burgerf77ed0ffa826
diff --git a/packages/bundler/src/bundle.ts b/packages/bundler/src/bundle.ts
index e84445839a..c6d458ce9c 100644
--- a/packages/bundler/src/bundle.ts
+++ b/packages/bundler/src/bundle.ts
@@ -44,7 +44,7 @@ export type BundleOptions = {
enableCaching?: boolean;
publicPath?: string;
rootDir?: string;
- publicDir?: string;
+ publicDir?: string | null;
};
export const getConfig = ({
diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.ts
index 15f9bc491c..0c70097192 100644
--- a/packages/cli/src/compositions.ts
+++ b/packages/cli/src/compositions.ts
@@ -51,6 +51,7 @@ export const listCompositionsCommand = async (remotionRoot: string) => {
inputProps,
puppeteerTimeout,
port,
+ publicDir,
} = await getCliOptions({
isLambda: false,
type: 'get-compositions',
@@ -61,6 +62,7 @@ export const listCompositionsCommand = async (remotionRoot: string) => {
remotionRoot,
fullPath,
steps: ['bundling'],
+ publicDir,
});
const compositions = await getCompositions(bundled, {
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index 226a9abb01..0f4426acfb 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -77,6 +77,7 @@ import {setOverwriteOutput} from './overwrite';
import {setPixelFormat} from './pixel-format';
import {setPort} from './preview-server';
import {setProResProfile} from './prores-profile';
+import {getPublicDir, setPublicDir} from './public-dir';
import {setQuality} from './quality';
import {setScale} from './scale';
import {setPuppeteerTimeout} from './timeout';
@@ -91,6 +92,7 @@ export const Config: ConfigType = {
overrideWebpackConfig,
setCachingEnabled: setWebpackCaching,
setPort,
+ setPublicDir,
},
Log: {
setLevel: setLogLevel,
@@ -172,6 +174,7 @@ export const ConfigInternals = {
getEnforceAudioTrack,
setEnforceAudioTrack,
getKeyboardShortcutsEnabled,
+ getPublicDir,
};
export const overrideRemotion = () => {
diff --git a/packages/cli/src/config/public-dir.ts b/packages/cli/src/config/public-dir.ts
new file mode 100644
index 0000000000..b236b269c7
--- /dev/null
+++ b/packages/cli/src/config/public-dir.ts
@@ -0,0 +1,9 @@
+let publicDir: string | null = null;
+
+export const getPublicDir = () => {
+ return publicDir;
+};
+
+export const setPublicDir = (dir: string) => {
+ publicDir = dir;
+};
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.ts
index eea71a08af..28f140c588 100644
--- a/packages/cli/src/get-cli-options.ts
+++ b/packages/cli/src/get-cli-options.ts
@@ -276,5 +276,6 @@ export const getCliOptions = async (options: {
muted: ConfigInternals.getMuted(),
enforceAudioTrack: ConfigInternals.getEnforceAudioTrack(),
keyboardShortcutsEnables: ConfigInternals.getKeyboardShortcutsEnabled(),
+ publicDir: ConfigInternals.getPublicDir(),
};
};
diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.ts
index ecdeb82157..7f74454396 100644
--- a/packages/cli/src/parse-command-line.ts
+++ b/packages/cli/src/parse-command-line.ts
@@ -31,6 +31,7 @@ export type CommandLineOptions = {
concurrency: number;
timeout: number;
config: string;
+ ['public-dir']: string;
crf: number;
force: boolean;
overwrite: boolean;
@@ -233,6 +234,10 @@ export const parseCommandLine = (
if (typeof parsedCli['enforce-audio-track'] !== 'undefined') {
Config.Rendering.setEnforceAudioTrack(parsedCli['enforce-audio-track']);
}
+
+ if (typeof parsedCli['public-dir'] !== 'undefined') {
+ Config.Bundling.setPublicDir(parsedCli['public-dir']);
+ }
};
export const quietFlagProvided = () => parsedCli.quiet || parsedCli.q;
diff --git a/packages/cli/src/preview-server/routes.ts b/packages/cli/src/preview-server/routes.ts
index 5e1afa881d..57e0f9dcf1 100644
--- a/packages/cli/src/preview-server/routes.ts
+++ b/packages/cli/src/preview-server/routes.ts
@@ -185,6 +185,7 @@ export const handleRoutes = ({
liveEventsServer,
getCurrentInputProps,
remotionRoot,
+ userPassedPublicDir,
}: {
hash: string;
hashPrefix: string;
@@ -193,6 +194,7 @@ export const handleRoutes = ({
liveEventsServer: LiveEventsServer;
getCurrentInputProps: () => object;
remotionRoot: string;
+ userPassedPublicDir: string | null;
}) => {
const url = new URL(request.url as string, 'http://localhost');
@@ -226,8 +228,10 @@ export const handleRoutes = ({
}
if (url.pathname.startsWith(hash)) {
- const root = path.join(remotionRoot, 'public');
- return serveStatic(root, hash, request, response);
+ const publicDir = userPassedPublicDir
+ ? path.resolve(remotionRoot, userPassedPublicDir)
+ : path.join(remotionRoot, 'public');
+ return serveStatic(publicDir, hash, request, response);
}
if (url.pathname.startsWith(hashPrefix)) {
diff --git a/packages/cli/src/preview-server/start-server.ts b/packages/cli/src/preview-server/start-server.ts
index 79188d4752..e7106049ad 100644
--- a/packages/cli/src/preview-server/start-server.ts
+++ b/packages/cli/src/preview-server/start-server.ts
@@ -18,13 +18,14 @@ export const startServer = async (
entry: string,
userDefinedComponent: string,
options: {
- webpackOverride?: WebpackOverrideFn;
+ webpackOverride: WebpackOverrideFn;
getCurrentInputProps: () => object;
envVariables?: Record<string, string>;
port: number | null;
maxTimelineTracks?: number;
remotionRoot: string;
keyboardShortcutsEnabled: boolean;
+ userPassedPublicDir: string | null;
}
): Promise<{
port: number;
@@ -83,6 +84,7 @@ export const startServer = async (
liveEventsServer,
getCurrentInputProps: options.getCurrentInputProps,
remotionRoot: options.remotionRoot,
+ userPassedPublicDir: options.userPassedPublicDir,
});
})
.catch((err) => {
diff --git a/packages/cli/src/preview.ts b/packages/cli/src/preview.ts
index b96c980fd9..843257fdf3 100644
--- a/packages/cli/src/preview.ts
+++ b/packages/cli/src/preview.ts
@@ -72,6 +72,8 @@ export const previewCommand = async (remotionRoot: string) => {
maxTimelineTracks: ConfigInternals.getMaxTimelineTracks(),
remotionRoot,
keyboardShortcutsEnabled: ConfigInternals.getKeyboardShortcutsEnabled(),
+ userPassedPublicDir: ConfigInternals.getPublicDir(),
+ webpackOverride: ConfigInternals.getWebpackOverrideFn(),
}
);
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 1c6f394ec4..beadafc6d1 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -78,6 +78,7 @@ export const render = async (remotionRoot: string) => {
puppeteerTimeout,
muted,
enforceAudioTrack,
+ publicDir,
} = await getCliOptions({
isLambda: false,
type: 'series',
@@ -130,6 +131,7 @@ export const render = async (remotionRoot: string) => {
fullPath,
remotionRoot,
steps,
+ publicDir,
}
);
diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.ts
index 507ae4fcdc..c5eed0fac7 100644
--- a/packages/cli/src/setup-cache.ts
+++ b/packages/cli/src/setup-cache.ts
@@ -14,10 +14,12 @@ export const bundleOnCliOrTakeServeUrl = async ({
fullPath,
remotionRoot,
steps,
+ publicDir,
}: {
fullPath: string;
remotionRoot: string;
steps: RenderStep[];
+ publicDir: string | null;
}): Promise<{
urlOrBundle: string;
cleanup: () => Promise<void>;
@@ -29,7 +31,7 @@ export const bundleOnCliOrTakeServeUrl = async ({
};
}
- const bundled = await bundleOnCli({fullPath, remotionRoot, steps});
+ const bundled = await bundleOnCli({fullPath, remotionRoot, steps, publicDir});
return {
urlOrBundle: bundled,
@@ -41,10 +43,12 @@ export const bundleOnCli = async ({
fullPath,
steps,
remotionRoot,
+ publicDir,
}: {
fullPath: string;
steps: RenderStep[];
remotionRoot: string;
+ publicDir: string | null;
}) => {
const shouldCache = ConfigInternals.getWebpackCaching();
@@ -62,6 +66,7 @@ export const bundleOnCli = async ({
enableCaching: shouldCache,
webpackOverride: ConfigInternals.getWebpackOverrideFn() ?? ((f) => f),
rootDir: remotionRoot,
+ publicDir,
};
const [hash] = BundlerInternals.getConfig({
diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.ts
index 2d0f86a54d..6c08505ea9 100644
--- a/packages/cli/src/still.ts
+++ b/packages/cli/src/still.ts
@@ -72,6 +72,7 @@ export const still = async (remotionRoot: string) => {
overwrite,
puppeteerTimeout,
port,
+ publicDir,
} = await getCliOptions({
isLambda: false,
type: 'still',
@@ -140,7 +141,7 @@ export const still = async (remotionRoot: string) => {
].filter(truthy);
const {cleanup: cleanupBundle, urlOrBundle} = await bundleOnCliOrTakeServeUrl(
- {fullPath, remotionRoot, steps}
+ {fullPath, remotionRoot, steps, publicDir}
);
const puppeteerInstance = await browserInstance;
diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts
index 2d75213c3d..b58fa4fcbe 100644
--- a/packages/core/src/config.ts
+++ b/packages/core/src/config.ts
@@ -60,6 +60,12 @@ export type ConfigType = {
* If you specify a port, but it's not available, Remotion will throw an error.
*/
readonly setPort: (port: number | undefined) => void;
+ /**
+ * Define the location of the public/ directory.
+ * By default it is a folder named "public" inside the current working directory.
+ * You can set an absolute path or a relative path that will be resolved from the closest package.json location.
+ */
+ readonly setPublicDir: (publicDir: string | null) => void;
};
readonly Log: {
/**