π₯ Make videos programmatically with React
`@remotion/bundler`: Separate Webpack and Rspack config overrides (#9523)
Jonny Burgerc881642d2a87
diff --git a/packages/brand/remotion.config.ts b/packages/brand/remotion.config.tsindex 2c962acaf6..9e59df84e5 100644--- a/packages/brand/remotion.config.ts+++ b/packages/brand/remotion.config.ts@@ -11,4 +11,4 @@ import {enableTailwind} from '@remotion/tailwind-v4';Config.setVideoImageFormat('jpeg');Config.setOverwriteOutput(true);Config.setChromiumOpenGlRenderer('angle');-Config.overrideWebpackConfig(enableTailwind);+Config.overrideBundlerConfig(enableTailwind);diff --git a/packages/bundler/src/bundle.ts b/packages/bundler/src/bundle.tsindex 7f19c729d1..ae05b32fb8 100644--- a/packages/bundler/src/bundle.ts+++ b/packages/bundler/src/bundle.ts@@ -8,10 +8,14 @@ import {getProjectName} from '@remotion/studio-shared';import webpack from 'webpack';import {copyDir} from './copy-dir';import {indexHtml} from './index-html';+import type {+ BundlerOverrideFn,+ RspackOverrideFn,+ WebpackOverrideFn,+} from './override-types';import {readRecursively} from './read-recursively';import {rspackConfig} from './rspack-config';import {clearCache} from './webpack-cache';-import type {WebpackOverrideFn} from './webpack-config';import {webpackConfig} from './webpack-config';const promisified = promisify(webpack);@@ -78,6 +82,8 @@ export const getBundleStaticHash = (publicPath: string): string => {};export type MandatoryLegacyBundleOptions = {+ bundlerOverride?: BundlerOverrideFn;+ rspackOverride?: RspackOverrideFn;webpackOverride: WebpackOverrideFn;outDir: string | null;enableCaching: boolean;@@ -124,7 +130,9 @@ export const getConfig = ({userDefinedComponent: entryPoint,outDir,environment: 'production' as const,+ bundlerOverride: options?.bundlerOverride ?? ((f) => f),webpackOverride: options?.webpackOverride ?? ((f) => f),+ rspackOverride: options?.rspackOverride ?? ((f) => f),onProgress: (p: number) => {onProgress?.(p);},@@ -435,7 +443,7 @@ export const internalBundle = async (};/*- * @description Bundles a Remotion project using Webpack and prepares it for rendering.+ * @description Bundles a Remotion project and prepares it for rendering.* @see [Documentation](https://remotion.dev/docs/bundle)*/export async function bundle(...args: Arguments): Promise<string> {@@ -456,6 +464,8 @@ export async function bundle(...args: Arguments): Promise<string> {publicDir: actualArgs.publicDir ?? null,publicPath: actualArgs.publicPath ?? null,rootDir: actualArgs.rootDir ?? null,+ bundlerOverride: actualArgs.bundlerOverride ?? ((f) => f),+ rspackOverride: actualArgs.rspackOverride ?? ((f) => f),webpackOverride: actualArgs.webpackOverride ?? ((f) => f),audioLatencyHint: actualArgs.audioLatencyHint ?? null,renderDefaults: actualArgs.renderDefaults ?? null,diff --git a/packages/bundler/src/index.ts b/packages/bundler/src/index.tsindex 338a6ca076..b8486eb71a 100644--- a/packages/bundler/src/index.ts+++ b/packages/bundler/src/index.ts@@ -29,6 +29,14 @@ export {LegacyBundleOptions,MandatoryLegacyBundleOptions,} from './bundle';-export {WebpackConfiguration, WebpackOverrideFn} from './webpack-config';+export type {+ BundlerConfiguration,+ BundlerName,+ BundlerOverrideFn,+ RspackConfiguration,+ RspackOverrideFn,+ WebpackConfiguration,+ WebpackOverrideFn,+} from './override-types';export {WatchIgnoreNextChangePlugin};export {webpack};diff --git a/packages/bundler/src/override-types.ts b/packages/bundler/src/override-types.tsnew file mode 100644index 0000000000..7b069a020b--- /dev/null+++ b/packages/bundler/src/override-types.ts@@ -0,0 +1,21 @@+import type {Configuration as RspackConfigurationType} from '@rspack/core';+import type {Configuration as WebpackConfigurationType} from 'webpack';++export type WebpackConfiguration = WebpackConfigurationType;+export type RspackConfiguration = RspackConfigurationType;+export type BundlerConfiguration = WebpackConfiguration | RspackConfiguration;++export type WebpackOverrideFn = (+ currentConfiguration: WebpackConfiguration,+) => WebpackConfiguration | Promise<WebpackConfiguration>;++export type RspackOverrideFn = (+ currentConfiguration: RspackConfiguration,+) => RspackConfiguration | Promise<RspackConfiguration>;++export type BundlerName = 'webpack' | 'rspack';++export type BundlerOverrideFn = <Configuration extends BundlerConfiguration>(+ currentConfiguration: Configuration,+ context: {bundler: BundlerName},+) => Configuration | Promise<Configuration>;diff --git a/packages/bundler/src/rspack-config.ts b/packages/bundler/src/rspack-config.tsindex cfe44d0384..e9871f76f0 100644--- a/packages/bundler/src/rspack-config.ts+++ b/packages/bundler/src/rspack-config.ts@@ -1,7 +1,11 @@import {getStudioEntryPoints} from '@remotion/studio-shared/studio-entry-points';-import type {Configuration} from '@rspack/core';import {ProgressPlugin, rspack} from '@rspack/core';import ReactRefreshPlugin from '@rspack/plugin-react-refresh';+import type {+ BundlerOverrideFn,+ RspackConfiguration,+ RspackOverrideFn,+} from './override-types';import {computeHashAndFinalConfig,getBaseConfig,@@ -9,16 +13,16 @@ import {getResolveConfig,getSharedModuleRules,} from './shared-bundler-config';-import type {WebpackOverrideFn} from './webpack-config';-export type RspackConfiguration = Configuration;+export type {RspackConfiguration, RspackOverrideFn} from './override-types';export const rspackConfig = async ({entry,userDefinedComponent,outDir,environment,- webpackOverride = (f) => f,+ bundlerOverride = (f) => f,+ rspackOverride = (f) => f,onProgress,enableCaching = true,remotionRoot,@@ -29,7 +33,8 @@ export const rspackConfig = async ({userDefinedComponent: string;outDir: string | null;environment: 'development' | 'production';- webpackOverride: WebpackOverrideFn;+ bundlerOverride: BundlerOverrideFn;+ rspackOverride: RspackOverrideFn;onProgress?: (f: number) => void;enableCaching?: boolean;remotionRoot: string;@@ -73,9 +78,7 @@ export const rspackConfig = async ({},};- // Rspack config is structurally compatible with webpack config at runtime,- // but the TypeScript types differ. Cast through `any` for the override.- const conf = (await webpackOverride({+ const baseConfig = {...getBaseConfig(environment, poll),node: {// Suppress the warning in `source-map`@@ -139,8 +142,9 @@ export const rspackConfig = async ({},],},- // eslint-disable-next-line @typescript-eslint/no-explicit-any- } as any)) as RspackConfiguration;+ } as RspackConfiguration;+ const sharedConfig = await bundlerOverride(baseConfig, {bundler: 'rspack'});+ const conf = await rspackOverride(sharedConfig as RspackConfiguration);const [hash, finalConf] = computeHashAndFinalConfig(conf, {enableCaching,diff --git a/packages/bundler/src/test/override-order.test.ts b/packages/bundler/src/test/override-order.test.tsnew file mode 100644index 0000000000..f115e61924--- /dev/null+++ b/packages/bundler/src/test/override-order.test.ts@@ -0,0 +1,60 @@+import {expect, test} from 'bun:test';+import type {+ BundlerOverrideFn,+ RspackOverrideFn,+ WebpackOverrideFn,+} from '../override-types';+import {rspackConfig} from '../rspack-config';+import {webpackConfig} from '../webpack-config';++const bundlerOverride: BundlerOverrideFn = (config, {bundler}) => ({+ ...config,+ name: `shared-${bundler}`,+});++const webpackOverride: WebpackOverrideFn = (config) => ({+ ...config,+ name: `${config.name}-webpack`,+});++const rspackOverride: RspackOverrideFn = (config) => ({+ ...config,+ name: `${config.name}-rspack`,+});++const baseOptions = {+ entry: require.resolve('@remotion/studio/renderEntry'),+ userDefinedComponent: require.resolve('@remotion/studio/renderEntry'),+ outDir: null,+ environment: 'production' as const,+ onProgress: () => undefined,+ enableCaching: false,+ maxTimelineTracks: null,+ remotionRoot: process.cwd(),+ keyboardShortcutsEnabled: true,+ bufferStateDelayInMilliseconds: null,+ poll: null,+ askAIEnabled: true,+ interactivityEnabled: true,+ extraPlugins: [],+};++test('applies the shared override before the Webpack override', async () => {+ const [, config] = await webpackConfig({+ ...baseOptions,+ bundlerOverride,+ webpackOverride,+ });++ expect(config.name).toBe('shared-webpack-webpack');+});++test('applies the shared override before the Rspack override', async () => {+ const [, config] = await rspackConfig({+ ...baseOptions,+ bundlerOverride,+ rspackOverride,+ });++ expect(config.name).toBe('shared-rspack-rspack');+});diff --git a/packages/bundler/src/webpack-config.ts b/packages/bundler/src/webpack-config.tsindex 5ee6efac73..b9fb6f6201 100644--- a/packages/bundler/src/webpack-config.ts+++ b/packages/bundler/src/webpack-config.ts@@ -1,5 +1,4 @@import {getStudioEntryPoints} from '@remotion/studio-shared/studio-entry-points';-import type {Configuration} from 'webpack';import webpack, {ProgressPlugin} from 'webpack';import {CaseSensitivePathsPlugin} from './case-sensitive-paths';import type {LoaderOptions} from './esbuild-loader/interfaces';@@ -7,6 +6,11 @@ import {ReactFreshWebpackPlugin} from './fast-refresh';import {AllowDependencyExpressionPlugin} from './hide-expression-dependency';import {IgnorePackFileCacheWarningsPlugin} from './ignore-packfilecache-warnings';import {AllowOptionalDependenciesPlugin} from './optional-dependencies';+import type {+ BundlerOverrideFn,+ WebpackConfiguration,+ WebpackOverrideFn,+} from './override-types';import {computeHashAndFinalConfig,getBaseConfig,@@ -15,11 +19,7 @@ import {getSharedModuleRules,} from './shared-bundler-config';import esbuild = require('esbuild');-export type WebpackConfiguration = Configuration;--export type WebpackOverrideFn = (- currentConfiguration: WebpackConfiguration,-) => WebpackConfiguration | Promise<WebpackConfiguration>;+export type {WebpackConfiguration, WebpackOverrideFn} from './override-types';type Truthy<T> = T extends false | '' | 0 | null | undefined ? never : T;@@ -32,6 +32,7 @@ export const webpackConfig = async ({userDefinedComponent,outDir,environment,+ bundlerOverride = (f) => f,webpackOverride = (f) => f,onProgress,enableCaching = true,@@ -43,6 +44,7 @@ export const webpackConfig = async ({userDefinedComponent: string;outDir: string | null;environment: 'development' | 'production';+ bundlerOverride: BundlerOverrideFn;webpackOverride: WebpackOverrideFn;onProgress?: (f: number) => void;enableCaching?: boolean;@@ -59,7 +61,7 @@ export const webpackConfig = async ({let lastProgress = 0;- const conf: WebpackConfiguration = await webpackOverride({+ const baseConfig: WebpackConfiguration = {...getBaseConfig(environment, poll),entry: getStudioEntryPoints({fastRefreshRuntime:@@ -137,7 +139,9 @@ export const webpackConfig = async ({},],},- });+ };+ const sharedConfig = await bundlerOverride(baseConfig, {bundler: 'webpack'});+ const conf = await webpackOverride(sharedConfig as WebpackConfiguration);return computeHashAndFinalConfig(conf, {enableCaching,diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.tsindex 980d98814b..1e2bcd4926 100644--- a/packages/cli/src/benchmark.ts+++ b/packages/cli/src/benchmark.ts@@ -346,6 +346,9 @@ export const benchmarkCommand = async (keyboardShortcutsEnabled,rspack,shouldCache,+ bundlerOverride: null,+ rspackOverride: null,+ webpackOverride: null,});registerCleanupJob(`Deleting bundle`, () => cleanupBundle());diff --git a/packages/cli/src/bundle.ts b/packages/cli/src/bundle.tsindex e83b18744f..48a2697b23 100644--- a/packages/cli/src/bundle.ts+++ b/packages/cli/src/bundle.ts@@ -157,6 +157,9 @@ export const bundleCommand = async (keyboardShortcutsEnabled,rspack,shouldCache,+ bundlerOverride: null,+ rspackOverride: null,+ webpackOverride: null,});Log.info(diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.tsindex 5be73a7d00..3640d79cee 100644--- a/packages/cli/src/compositions.ts+++ b/packages/cli/src/compositions.ts@@ -163,6 +163,9 @@ export const listCompositionsCommand = async (keyboardShortcutsEnabled,rspack,shouldCache,+ bundlerOverride: null,+ rspackOverride: null,+ webpackOverride: null,});registerCleanupJob(`Cleanup bundle`, () => cleanupBundle());diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.tsindex 1ebed5aff0..057da54f63 100644--- a/packages/cli/src/config/index.ts+++ b/packages/cli/src/config/index.ts@@ -1,4 +1,10 @@-import type {WebpackConfiguration} from '@remotion/bundler';+import type {+ BundlerOverrideFn,+ RspackConfiguration,+ RspackOverrideFn,+ WebpackConfiguration,+ WebpackOverrideFn,+} from '@remotion/bundler';import type {BrowserExecutable,ChromeMode,@@ -37,12 +43,17 @@ import {resetOutputLocation,setOutputLocation,} from './output-location';-import type {WebpackOverrideFn} from './override-webpack';import {+ defaultBundlerOverrideFunction,defaultOverrideFunction,+ defaultRspackOverrideFunction,+ getBundlerOverrideFn,+ getRspackOverrideFn,getWebpackOverrideFn,+ overrideBundlerConfig,+ overrideRspackConfig,overrideWebpackConfig,- resetWebpackOverride,+ resetBundlerOverrides,} from './override-webpack';import {getRendererPortFromConfigFile,@@ -57,7 +68,14 @@ import {getStillFrame, resetStillFrame, setStillFrame} from './still-frame';import {getWebpackCaching} from './webpack-caching';import {getWebpackPolling} from './webpack-poll';-export type {Concurrency, WebpackConfiguration, WebpackOverrideFn};+export type {+ BundlerOverrideFn,+ Concurrency,+ RspackConfiguration,+ RspackOverrideFn,+ WebpackConfiguration,+ WebpackOverrideFn,+};const {benchmarkConcurrenciesOption,@@ -172,6 +190,8 @@ declare global {* 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 overrideBundlerConfig: (f: BundlerOverrideFn) => void;+ readonly overrideRspackConfig: (f: RspackOverrideFn) => void;readonly overrideWebpackConfig: (f: WebpackOverrideFn) => void;}// Legacy config format: New options to not need to be added here.@@ -723,6 +743,8 @@ export const Config: FlatConfig = {setWebpackPollingInMilliseconds: webpackPollOption.setConfig,setShouldOpenBrowser: noOpenOption.setConfig,setBufferStateDelayInMilliseconds,+ overrideBundlerConfig,+ overrideRspackConfig,overrideWebpackConfig,setCachingEnabled: bundleCacheOption.setConfig,setPort,@@ -871,7 +893,7 @@ const resetConfigOptions = () => {resetFfmpegOverrideFunction();resetMetadata();resetOutputLocation();- resetWebpackOverride();+ resetBundlerOverrides();resetPreviewServerPorts();resetStillFrame();};@@ -885,12 +907,16 @@ export const ConfigInternals = {getStillFrame,getShouldOutputImageSequence,getDotEnvLocation,+ getBundlerOverrideFn,+ getRspackOverrideFn,getWebpackOverrideFn,getWebpackCaching,getOutputLocation,setStillFrame,getMaxTimelineTracks: StudioServerInternals.getMaxTimelineTracks,defaultOverrideFunction,+ defaultBundlerOverrideFunction,+ defaultRspackOverrideFunction,getFfmpegOverrideFunction,getMetadata,getEntryPoint,diff --git a/packages/cli/src/config/override-webpack.ts b/packages/cli/src/config/override-webpack.tsindex e808b8dc3d..701fd2567a 100644--- a/packages/cli/src/config/override-webpack.ts+++ b/packages/cli/src/config/override-webpack.ts@@ -1,21 +1,55 @@-import type {WebpackConfiguration} from '@remotion/bundler';+import type {+ BundlerOverrideFn,+ RspackOverrideFn,+ WebpackOverrideFn,+} from '@remotion/bundler';-export type WebpackOverrideFn = (- currentConfiguration: WebpackConfiguration,-) => WebpackConfiguration | Promise<WebpackConfiguration>;+export type {+ BundlerOverrideFn,+ RspackOverrideFn,+ WebpackOverrideFn,+} from '@remotion/bundler';export const defaultOverrideFunction: WebpackOverrideFn = (config) => config;-let overrideFn: WebpackOverrideFn = defaultOverrideFunction;+export const defaultRspackOverrideFunction: RspackOverrideFn = (config) =>+ config;+export const defaultBundlerOverrideFunction: BundlerOverrideFn = (config) =>+ config;++let webpackOverrideFn: WebpackOverrideFn = defaultOverrideFunction;+let rspackOverrideFn: RspackOverrideFn = defaultRspackOverrideFunction;+let bundlerOverrideFn: BundlerOverrideFn = defaultBundlerOverrideFunction;export const getWebpackOverrideFn = () => {- return overrideFn;+ return webpackOverrideFn;+};++export const getRspackOverrideFn = () => {+ return rspackOverrideFn;+};++export const getBundlerOverrideFn = () => {+ return bundlerOverrideFn;};export const overrideWebpackConfig = (fn: WebpackOverrideFn) => {- const prevOverride = overrideFn;- overrideFn = async (c) => fn(await prevOverride(c));+ const prevOverride = webpackOverrideFn;+ webpackOverrideFn = async (c) => fn(await prevOverride(c));+};++export const overrideRspackConfig = (fn: RspackOverrideFn) => {+ const prevOverride = rspackOverrideFn;+ rspackOverrideFn = async (c) => fn(await prevOverride(c));+};++export const overrideBundlerConfig = (fn: BundlerOverrideFn) => {+ const prevOverride = bundlerOverrideFn;+ bundlerOverrideFn = async (c, context) =>+ fn(await prevOverride(c, context), context);};-export const resetWebpackOverride = () => {- overrideFn = defaultOverrideFunction;+export const resetBundlerOverrides = () => {+ webpackOverrideFn = defaultOverrideFunction;+ rspackOverrideFn = defaultRspackOverrideFunction;+ bundlerOverrideFn = defaultBundlerOverrideFunction;};diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.tsindex 0ede6efd90..eb1ba18d50 100644--- a/packages/cli/src/render-flows/render.ts+++ b/packages/cli/src/render-flows/render.ts@@ -1,6 +1,11 @@import fs, {existsSync} from 'node:fs';import os from 'node:os';import path from 'node:path';+import type {+ BundlerOverrideFn,+ RspackOverrideFn,+ WebpackOverrideFn,+} from '@remotion/bundler';import type {AudioCodec,Browser,@@ -131,6 +136,9 @@ export const renderVideoFlow = async ({keyboardShortcutsEnabled,shouldCache,sampleRate,+ bundlerOverride,+ rspackOverride,+ webpackOverride,}: {remotionRoot: string;fullEntryPoint: string;@@ -199,6 +207,9 @@ export const renderVideoFlow = async ({keyboardShortcutsEnabled: boolean;shouldCache: boolean;sampleRate: number;+ bundlerOverride: BundlerOverrideFn | null;+ rspackOverride: RspackOverrideFn | null;+ webpackOverride: WebpackOverrideFn | null;}) => {RenderInternals.validateConcurrency({value: concurrency,@@ -350,6 +361,9 @@ export const renderVideoFlow = async ({keyboardShortcutsEnabled,rspack,shouldCache,+ bundlerOverride,+ rspackOverride,+ webpackOverride,},);diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.tsindex 496143d710..8a4a85f430 100644--- a/packages/cli/src/render-flows/still.ts+++ b/packages/cli/src/render-flows/still.ts@@ -2,6 +2,11 @@import {existsSync, mkdirSync} from 'node:fs';import path from 'node:path';+import type {+ BundlerOverrideFn,+ RspackOverrideFn,+ WebpackOverrideFn,+} from '@remotion/bundler';import type {Browser,BrowserExecutable,@@ -88,6 +93,9 @@ export const renderStillFlow = async ({askAIEnabled,keyboardShortcutsEnabled,shouldCache,+ bundlerOverride,+ rspackOverride,+ webpackOverride,}: {remotionRoot: string;fullEntryPoint: string;@@ -128,6 +136,9 @@ export const renderStillFlow = async ({askAIEnabled: boolean;keyboardShortcutsEnabled: boolean;shouldCache: boolean;+ bundlerOverride: BundlerOverrideFn | null;+ rspackOverride: RspackOverrideFn | null;+ webpackOverride: WebpackOverrideFn | null;}) => {const isVerbose = RenderInternals.isEqualOrBelowLogLevel(logLevel, 'verbose');Log.verbose(@@ -233,6 +244,9 @@ export const renderStillFlow = async ({keyboardShortcutsEnabled,rspack,shouldCache,+ bundlerOverride,+ rspackOverride,+ webpackOverride,},);diff --git a/packages/cli/src/render-queue/process-still.ts b/packages/cli/src/render-queue/process-still.tsindex e7774d57ef..d169b3339f 100644--- a/packages/cli/src/render-queue/process-still.ts+++ b/packages/cli/src/render-queue/process-still.ts@@ -86,5 +86,8 @@ export const processStill = async ({keyboardShortcutsEnabled,rspack: fixedConfig.rspack,shouldCache,+ bundlerOverride: fixedConfig.bundlerOverride,+ rspackOverride: fixedConfig.rspackOverride,+ webpackOverride: fixedConfig.webpackOverride,});};diff --git a/packages/cli/src/render-queue/process-video.ts b/packages/cli/src/render-queue/process-video.tsindex 616ee980ac..82887e31c8 100644--- a/packages/cli/src/render-queue/process-video.ts+++ b/packages/cli/src/render-queue/process-video.ts@@ -131,5 +131,8 @@ export const processVideoJob = async ({keyboardShortcutsEnabled,rspack: fixedConfig.rspack,shouldCache,+ bundlerOverride: fixedConfig.bundlerOverride,+ rspackOverride: fixedConfig.rspackOverride,+ webpackOverride: fixedConfig.webpackOverride,});};diff --git a/packages/cli/src/render-queue/studio-render-job-fixed-config.ts b/packages/cli/src/render-queue/studio-render-job-fixed-config.tsindex b0ef66f41c..18c7d0ed71 100644--- a/packages/cli/src/render-queue/studio-render-job-fixed-config.ts+++ b/packages/cli/src/render-queue/studio-render-job-fixed-config.ts@@ -1,5 +1,14 @@+import type {+ BundlerOverrideFn,+ RspackOverrideFn,+ WebpackOverrideFn,+} from '@remotion/bundler';+export type StudioRenderJobFixedConfig = {+ readonly bundlerOverride: BundlerOverrideFn;readonly publicDir: string | null;readonly rendererPort: number | null;+ readonly rspackOverride: RspackOverrideFn;readonly rspack: boolean;+ readonly webpackOverride: WebpackOverrideFn;};diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 7b49713b7d..4a1c852918 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -325,5 +325,8 @@ export const render = async (rspack,sampleRate,shouldCache,+ bundlerOverride: null,+ rspackOverride: null,+ webpackOverride: null,});};diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.tsindex 8563ae5cf7..acc0b97e74 100644--- a/packages/cli/src/setup-cache.ts+++ b/packages/cli/src/setup-cache.ts@@ -1,6 +1,11 @@import {existsSync} from 'fs';import path from 'path';-import type {MandatoryLegacyBundleOptions} from '@remotion/bundler';+import type {+ BundlerOverrideFn,+ MandatoryLegacyBundleOptions,+ RspackOverrideFn,+ WebpackOverrideFn,+} from '@remotion/bundler';import {BundlerInternals} from '@remotion/bundler';import type {LogLevel} from '@remotion/renderer';import {RenderInternals} from '@remotion/renderer';@@ -36,6 +41,9 @@ export const bundleOnCliOrTakeServeUrl = async ({keyboardShortcutsEnabled,rspack,shouldCache,+ bundlerOverride,+ rspackOverride,+ webpackOverride,}: {fullPath: string;remotionRoot: string;@@ -59,6 +67,9 @@ export const bundleOnCliOrTakeServeUrl = async ({keyboardShortcutsEnabled: boolean;rspack: boolean;shouldCache: boolean;+ bundlerOverride: BundlerOverrideFn | null;+ rspackOverride: RspackOverrideFn | null;+ webpackOverride: WebpackOverrideFn | null;}): Promise<{urlOrBundle: string;cleanup: () => void;@@ -103,6 +114,9 @@ export const bundleOnCliOrTakeServeUrl = async ({keyboardShortcutsEnabled,rspack,shouldCache,+ bundlerOverride,+ rspackOverride,+ webpackOverride,});return {@@ -131,6 +145,9 @@ export const bundleOnCli = async ({keyboardShortcutsEnabled,rspack,shouldCache,+ bundlerOverride,+ rspackOverride,+ webpackOverride,}: {fullPath: string;remotionRoot: string;@@ -154,6 +171,9 @@ export const bundleOnCli = async ({askAIEnabled: boolean;rspack: boolean;shouldCache: boolean;+ bundlerOverride: BundlerOverrideFn | null;+ rspackOverride: RspackOverrideFn | null;+ webpackOverride: WebpackOverrideFn | null;}) => {const symlinkState: SymbolicLinksState = {symlinks: [],@@ -208,7 +228,10 @@ export const bundleOnCli = async ({const options: MandatoryLegacyBundleOptions = {enableCaching: shouldCache,- webpackOverride: ConfigInternals.getWebpackOverrideFn() ?? ((f) => f),+ bundlerOverride: bundlerOverride ?? ConfigInternals.getBundlerOverrideFn(),+ rspackOverride: rspackOverride ?? ConfigInternals.getRspackOverrideFn(),+ webpackOverride:+ webpackOverride ?? ConfigInternals.getWebpackOverrideFn() ?? ((f) => f),rootDir: remotionRoot,publicDir,onPublicDirCopyProgress,diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.tsindex fcd9eb6ec4..d36d967646 100644--- a/packages/cli/src/still.ts+++ b/packages/cli/src/still.ts@@ -218,5 +218,8 @@ export const still = async (keyboardShortcutsEnabled,rspack,shouldCache,+ bundlerOverride: null,+ rspackOverride: null,+ webpackOverride: null,});};diff --git a/packages/cli/src/studio.ts b/packages/cli/src/studio.tsindex 8783e4f473..480c933284 100644--- a/packages/cli/src/studio.ts+++ b/packages/cli/src/studio.ts@@ -162,6 +162,9 @@ export const studioCommand = async (const gitSource = getGitSource({remotionRoot, disableGitSource, logLevel});const useRspack = rspackOption.getValue({commandLine: parsedCli}).value;+ const bundlerOverride = ConfigInternals.getBundlerOverrideFn();+ const rspackOverride = ConfigInternals.getRspackOverrideFn();+ const webpackOverride = ConfigInternals.getWebpackOverrideFn();if (useRspack) {Log.warn(@@ -203,7 +206,9 @@ export const studioCommand = async (desiredPort,remotionRoot,relativePublicDir,- webpackOverride: ConfigInternals.getWebpackOverrideFn(),+ bundlerOverride,+ rspackOverride,+ webpackOverride,poll: webpackPollOption.getValue({commandLine: parsedCli}).value,getRenderDefaults: () => getRenderDefaults(logLevel),getRenderQueue,@@ -213,9 +218,12 @@ export const studioCommand = async (addJob({...options,fixedConfig: {+ bundlerOverride,publicDir: relativePublicDir,rendererPort,+ rspackOverride,rspack: useRspack,+ webpackOverride,},}),cancelJob,diff --git a/packages/cli/src/test/config-reset.test.ts b/packages/cli/src/test/config-reset.test.tsindex 8446978ab6..1263e8867f 100644--- a/packages/cli/src/test/config-reset.test.ts+++ b/packages/cli/src/test/config-reset.test.ts@@ -2,6 +2,7 @@ import {expect, test} from 'bun:test';import {BrowserSafeApis} from '@remotion/renderer/client';import {StudioServerInternals} from '@remotion/studio-server';import {DEFAULT_TIMELINE_TRACKS} from '@remotion/studio-shared';+import type {RspackConfiguration, WebpackConfiguration} from '../config';import {Config, ConfigInternals} from '../config';import {getRenderDefaults} from '../get-render-defaults';@@ -19,14 +20,22 @@ test('reset config options restores defaults before reloading config', async ()Config.setMaxTimelineTracks(123);Config.setChromiumOpenGlRenderer('angle');Config.setBufferStateDelayInMilliseconds(200);+ Config.overrideBundlerConfig((config, {bundler}) => ({+ ...config,+ name: `shared-${bundler}`,+ }));Config.overrideWebpackConfig((config) => ({...config,- name: 'first',+ name: `${config.name}-webpack`,}));Config.overrideWebpackConfig((config) => ({...config,devtool: 'source-map',}));+ Config.overrideRspackConfig((config) => ({+ ...config,+ name: `${config.name}-rspack`,+ }));expect(ConfigInternals.getStudioPort()).toBe(4321);expect(StudioServerInternals.getMaxTimelineTracks()).toBe(123);@@ -34,9 +43,31 @@ test('reset config options restores defaults before reloading config', async ()BrowserSafeApis.options.glOption.getValue({commandLine: {}}).value,).toBe('angle');expect(ConfigInternals.getBufferStateDelayInMilliseconds()).toBe(200);+ const sharedWebpackConfig = await ConfigInternals.getBundlerOverrideFn()(+ {mode: 'development'},+ {bundler: 'webpack'},+ );expect(- await ConfigInternals.getWebpackOverrideFn()({mode: 'development'}),- ).toEqual({mode: 'development', name: 'first', devtool: 'source-map'});+ await ConfigInternals.getWebpackOverrideFn()(+ sharedWebpackConfig as WebpackConfiguration,+ ),+ ).toEqual({+ mode: 'development',+ name: 'shared-webpack-webpack',+ devtool: 'source-map',+ });+ const sharedRspackConfig = await ConfigInternals.getBundlerOverrideFn()(+ {mode: 'development'},+ {bundler: 'rspack'},+ );+ expect(+ await ConfigInternals.getRspackOverrideFn()(+ sharedRspackConfig as RspackConfiguration,+ ),+ ).toEqual({+ mode: 'development',+ name: 'shared-rspack-rspack',+ });ConfigInternals.resetConfigOptions();@@ -48,9 +79,18 @@ test('reset config options restores defaults before reloading config', async ()BrowserSafeApis.options.glOption.getValue({commandLine: {}}).value,).toBeNull();expect(ConfigInternals.getBufferStateDelayInMilliseconds()).toBeNull();+ expect(+ await ConfigInternals.getBundlerOverrideFn()(+ {mode: 'development'},+ {bundler: 'webpack'},+ ),+ ).toEqual({mode: 'development'});expect(await ConfigInternals.getWebpackOverrideFn()({mode: 'development'}),).toEqual({mode: 'development'});+ expect(+ await ConfigInternals.getRspackOverrideFn()({mode: 'development'}),+ ).toEqual({mode: 'development'});expect(BrowserSafeApis.options.askAIOption.getValue({commandLine: {}}).value,).toBe(true);@@ -65,3 +105,30 @@ test('reset config options restores defaults before reloading config', async ().value,).toBe(true);});++test('bundler overrides can be fixed at Studio startup', async () => {+ ConfigInternals.resetConfigOptions();+ Config.overrideBundlerConfig((config) => ({...config, name: 'startup'}));+ Config.overrideRspackConfig((config) => ({+ ...config,+ devtool: 'source-map',+ }));++ const startupBundlerOverride = ConfigInternals.getBundlerOverrideFn();+ const startupRspackOverride = ConfigInternals.getRspackOverrideFn();++ Config.overrideBundlerConfig((config) => ({...config, name: 'reloaded'}));+ Config.overrideRspackConfig((config) => ({...config, devtool: false}));++ const sharedConfig = await startupBundlerOverride(+ {mode: 'development'},+ {bundler: 'rspack'},+ );+ expect(+ await startupRspackOverride(sharedConfig as RspackConfiguration),+ ).toEqual({+ mode: 'development',+ name: 'startup',+ devtool: 'source-map',+ });+});diff --git a/packages/cloudrun/src/api/deploy-site.ts b/packages/cloudrun/src/api/deploy-site.tsindex 0c22abce60..38a687050d 100644--- a/packages/cloudrun/src/api/deploy-site.ts+++ b/packages/cloudrun/src/api/deploy-site.ts@@ -1,6 +1,8 @@import {BundlerInternals,+ type BundlerOverrideFn,type GitSource,+ type RspackOverrideFn,type WebpackOverrideFn,} from '@remotion/bundler';import type {ToOptions} from '@remotion/renderer';@@ -21,6 +23,8 @@ import {uploadDir} from './upload-dir';type Options = {onBundleProgress?: (progress: number) => void;onUploadProgress?: (upload: UploadDirProgress) => void;+ bundlerOverride?: BundlerOverrideFn;+ rspackOverride?: RspackOverrideFn;webpackOverride?: WebpackOverrideFn;ignoreRegisterRootWarning?: boolean;enableCaching?: boolean;@@ -91,6 +95,8 @@ export const internalDeploySiteRaw = async ({}),BundlerInternals.internalBundle({publicPath: `/${bucketName}/${subFolder}/`,+ bundlerOverride: options?.bundlerOverride ?? ((f) => f),+ rspackOverride: options?.rspackOverride ?? ((f) => f),webpackOverride: options?.webpackOverride ?? ((f) => f),enableCaching: options?.enableCaching ?? true,publicDir: options?.publicDir ?? null,diff --git a/packages/cloudrun/src/cli/commands/sites/create.ts b/packages/cloudrun/src/cli/commands/sites/create.tsindex 973b8a4165..a9c5dc35c4 100644--- a/packages/cloudrun/src/cli/commands/sites/create.ts+++ b/packages/cloudrun/src/cli/commands/sites/create.ts@@ -185,6 +185,8 @@ export const sitesCreateSubcommand = async (enableCaching: BrowserSafeApis.options.bundleCacheOption.getValue({commandLine: CliInternals.parsedCli,}).value,+ bundlerOverride: ConfigInternals.getBundlerOverrideFn(),+ rspackOverride: ConfigInternals.getRspackOverrideFn(),webpackOverride: ConfigInternals.getWebpackOverrideFn() ?? ((f) => f),gitSource,bypassBucketNameValidation: true,diff --git a/packages/docs/blog/2021-02-11-remotion1-1.mdx b/packages/docs/blog/2021-02-11-remotion1-1.mdxindex cc77bcfd57..67fce8d12d 100644--- a/packages/docs/blog/2021-02-11-remotion1-1.mdx+++ b/packages/docs/blog/2021-02-11-remotion1-1.mdx@@ -13,7 +13,7 @@ Now it's time to iterate and make Remotion better. This release contains two new## Customizing Webpack configuration-**[See docs](/docs/webpack)**+**[See docs](/docs/bundlers)**People had wild ideas on what to do with Remotion like importing MDX files or using React Native components. Now it is possible!diff --git a/packages/docs/blog/2022-04-26-remotion-3-0.mdx b/packages/docs/blog/2022-04-26-remotion-3-0.mdxindex 0982832717..055de300b1 100644--- a/packages/docs/blog/2022-04-26-remotion-3-0.mdx+++ b/packages/docs/blog/2022-04-26-remotion-3-0.mdx@@ -56,7 +56,7 @@ We are taking an initiative to make error easier to understand. While much of er## Config file can now import other files.-In the `remotion.config.ts` file, you can now import other files. Under the hood, we use ESBuild instead of Typescript to read the file. This was a paint point before: Node.JS APIs don't read from the config file and require you to specify the options explicitly. Configuration such as a [Webpack config override](/docs/webpack) could not be shared in a good way between CLI and Node.JS renders so far, which we address with this change.+In the `remotion.config.ts` file, you can now import other files. Under the hood, we use ESBuild instead of Typescript to read the file. This was a paint point before: Node.JS APIs don't read from the config file and require you to specify the options explicitly. Configuration such as a [Webpack config override](/docs/bundlers) could not be shared in a good way between CLI and Node.JS renders so far, which we address with this change.## React 18 supporteddiff --git a/packages/docs/docs/bundle.mdx b/packages/docs/docs/bundle.mdxindex 80d023eb42..83f9f10a6d 100644--- a/packages/docs/docs/bundle.mdx+++ b/packages/docs/docs/bundle.mdx@@ -7,7 +7,7 @@ crumb: '@remotion/bundler'_Part of the `@remotion/bundler` package._-Bundles a Remotion project using Webpack and prepares it for rendering using [`renderMedia()`](/docs/renderer/render-media). [See a full server-side rendering example.](/docs/ssr-node)+Bundles a Remotion project using Webpack, or Rspack if enabled, and prepares it for rendering using [`renderMedia()`](/docs/renderer/render-media). [See a full server-side rendering example.](/docs/ssr-node)You only need to call this function when the source code changes. You can render multiple videos from the same bundle and parametrize them using [input props](/docs/passing-props).@@ -22,7 +22,7 @@ import {bundle} from '@remotion/bundler';const serveUrl = await bundle({entryPoint: path.join(process.cwd(), './src/index.ts'),- // If you have a webpack override in remotion.config.ts, pass it here as well.+ // If you have a bundler override in remotion.config.ts, pass it here as well.webpackOverride: (config) => config,});```@@ -35,17 +35,17 @@ A `string` containing an absolute path of the entry point of a Remotion project.### `onProgress?`-A callback function that notifies about the progress of the Webpack bundling. Passes a number between `0` and `100`. Example function:+A callback function that notifies about the bundling progress. Passes a number between `0` and `100`. Example function:```ts twoslashconst onProgress = (progress: number) => {- console.log(`Webpack bundling progress: ${progress}%`);+ console.log(`Bundling progress: ${progress}%`);};```### `webpackOverride?`-A function to override the webpack config reducer-style. Takes a function which gives you the current webpack config which you can transform and return a modified version of it. For example:+A function to override the Webpack config reducer-style. It is not called if `rspack` is `true`. For example:```ts twoslashimport {WebpackOverrideFn} from '@remotion/bundler';@@ -58,9 +58,41 @@ const webpackOverride: WebpackOverrideFn = (webpackConfig) => {};```+### `bundlerOverride?`<AvailableFrom v="4.0.498" />++A function that overrides configuration shared by Webpack and Rspack. The second argument identifies the selected bundler.++Use it only for changes compatible with both bundlers. It runs before `webpackOverride` or `rspackOverride`.++```ts twoslash+import {BundlerOverrideFn} from '@remotion/bundler';+// ---cut---+const bundlerOverride: BundlerOverrideFn = (config, {bundler}) => {+ return {+ ...config,+ name: `remotion-${bundler}`,+ };+};+```++### `rspackOverride?`<AvailableFrom v="4.0.498" />++A function to override the Rspack config reducer-style. It is only called if `rspack` is `true`.++```ts twoslash+import {RspackOverrideFn} from '@remotion/bundler';+// ---cut---+const rspackOverride: RspackOverrideFn = (rspackConfig) => {+ return {+ ...rspackConfig,+ // Rspack-specific configuration+ };+};+```+### `outDir?`-Specify a desired output directory. If no passed, the webpack bundle will be created in a temp dir.+Specify a desired output directory. If not passed, the bundle will be created in a temporary directory.### `askAIEnabled?`@@ -117,6 +149,8 @@ const bundle: (entryPoint: string,onProgress?: (progress: number) => void,options?: {+ bundlerOverride?: BundlerOverrideFn;+ rspackOverride?: RspackOverrideFn;webpackOverride?: WebpackOverrideFn;outDir?: string;enableCaching?: boolean;diff --git a/packages/docs/docs/cloudrun/deploysite.mdx b/packages/docs/docs/cloudrun/deploysite.mdxindex a535bcbde7..bca0e98182 100644--- a/packages/docs/docs/cloudrun/deploysite.mdx+++ b/packages/docs/docs/cloudrun/deploysite.mdx@@ -79,7 +79,15 @@ Callback function that gets called when uploading of the assets has progressed.#### `webpackOverride?`-Allows to pass a custom webpack override. See [`bundle()` -> webpackOverride](/docs/bundle#webpackoverride) for more information.+Passes a custom Webpack override. It is ignored if `rspack` is `true`. See [`bundle()` β `webpackOverride`](/docs/bundle#webpackoverride).++#### `bundlerOverride?`<AvailableFrom v="4.0.498" />++Passes an override shared by Webpack and Rspack. See [`bundle()` β `bundlerOverride`](/docs/bundle#bundleroverride).++#### `rspackOverride?`<AvailableFrom v="4.0.498" />++Passes a custom Rspack override. See [`bundle()` β `rspackOverride`](/docs/bundle#rspackoverride).#### `enableCaching?`diff --git a/packages/docs/docs/config.mdx b/packages/docs/docs/config.mdxindex ec50551914..67b7ab07d8 100644--- a/packages/docs/docs/config.mdx+++ b/packages/docs/docs/config.mdx@@ -23,9 +23,30 @@ Config.setPixelFormat('yuv444p');Config.setCodec('h265');```+## `overrideBundlerConfig()`<AvailableFrom v="4.0.498" />++Overrides configuration shared by Webpack and Rspack.++The callback receives the current configuration and a context object containing `bundler`, which is either `'webpack'` or `'rspack'`.++Use this option only for changes that are compatible with both bundlers. Bundler-specific plugins and options should use `overrideWebpackConfig()` or `overrideRspackConfig()` instead.++```ts twoslash title="remotion.config.ts"+import {Config} from '@remotion/cli/config';+// ---cut---+Config.overrideBundlerConfig((currentConfiguration, {bundler}) => {+ return {+ ...currentConfiguration,+ name: `remotion-${bundler}`,+ };+});+```++The shared override runs before the selected bundler's specific override.+## `overrideWebpackConfig()`<AvailableFrom v="1.1.0" />-Allows you to insert your custom Webpack config. [See the page about custom Webpack configs](/docs/webpack) for more information.+See [Webpack and Rspack](/docs/bundlers) for usage and examples.```ts twoslash title="remotion.config.ts"import {Config} from '@remotion/cli/config';@@ -39,6 +60,23 @@ Config.overrideWebpackConfig((currentConfiguration) => {});```+## `overrideRspackConfig()`<AvailableFrom v="4.0.498" />++Overrides the Rspack configuration. It is only called when [Rspack](/docs/config#setexperimentalrspackenabled) is enabled.++```ts twoslash title="remotion.config.ts"+import {Config} from '@remotion/cli/config';+// ---cut---+Config.overrideRspackConfig((currentConfiguration) => {+ return {+ ...currentConfiguration,+ // Rspack-specific configuration+ };+});+```++If `overrideBundlerConfig()` is also set, the shared override runs first.+## `setCachingEnabled()`<AvailableFrom v="2.0.0" /><Options id="bundle-cache" />@@ -195,7 +233,7 @@ From Remotion v4.0.491, this method is a no-op and can be removed from your conf## `setExperimentalRspackEnabled()`<AvailableFrom v="4.0.426" />-Use [Rspack](https://rspack.dev) instead of Webpack as the bundler for the Studio. Default `false`.+Use [Rspack](/docs/bundlers#enable-rspack) instead of Webpack for CLI commands that bundle your project. Default `false`.```ts twoslash title="remotion.config.ts"import {Config} from '@remotion/cli/config';diff --git a/packages/docs/docs/enable-scss/overview.mdx b/packages/docs/docs/enable-scss/overview.mdxindex 37af3e8b2d..86ecd2b27f 100644--- a/packages/docs/docs/enable-scss/overview.mdx+++ b/packages/docs/docs/enable-scss/overview.mdx@@ -26,7 +26,7 @@ Newer versions may not work.## Usage-[Override the Webpack config](/docs/webpack) by using [`enableScss()`](/docs/enable-scss/enable-scss).+[Override the bundler config](/docs/bundlers) by using [`enableScss()`](/docs/enable-scss/enable-scss).```ts twoslash title="remotion.config.ts"import {Config} from '@remotion/cli/config';diff --git a/packages/docs/docs/importing-assets.mdx b/packages/docs/docs/importing-assets.mdxindex 59ea1712b1..83189701df 100644--- a/packages/docs/docs/importing-assets.mdx+++ b/packages/docs/docs/importing-assets.mdx@@ -145,7 +145,7 @@ import './style.css';```:::note-Want to use SASS, Tailwind or similar? [See examples on how to override the Webpack configuration](/docs/webpack).+Want to use SASS, Tailwind or similar? [See examples on how to override the bundler configuration](/docs/bundlers).:::## Using Fontsdiff --git a/packages/docs/docs/jsx-support.mdx b/packages/docs/docs/jsx-support.mdxindex 09733f61d4..487e4e81ca 100644--- a/packages/docs/docs/jsx-support.mdx+++ b/packages/docs/docs/jsx-support.mdx@@ -22,4 +22,4 @@ If you upgrade from Remotion 1.2 or older, consider changing the `npm test` comm## See also-- [Custom Webpack config](/docs/webpack) for more advanced tweaking+- [Custom bundler config](/docs/bundlers) for more advanced tweakingdiff --git a/packages/docs/docs/lambda/deploysite.mdx b/packages/docs/docs/lambda/deploysite.mdxindex 0e5820241c..49e4ed23eb 100644--- a/packages/docs/docs/lambda/deploysite.mdx+++ b/packages/docs/docs/lambda/deploysite.mdx@@ -80,7 +80,15 @@ Callback function that gets called when uploading of the assets has progressed.#### `webpackOverride?`-Allows to pass a custom webpack override. See [`bundle()` -> webpackOverride](/docs/bundle#webpackoverride) for more information.+Passes a custom Webpack override. It is ignored if `rspack` is `true`. See [`bundle()` β `webpackOverride`](/docs/bundle#webpackoverride).++#### `bundlerOverride?`<AvailableFrom v="4.0.498" />++Passes an override shared by Webpack and Rspack. See [`bundle()` β `bundlerOverride`](/docs/bundle#bundleroverride).++#### `rspackOverride?`<AvailableFrom v="4.0.498" />++Passes a custom Rspack override. See [`bundle()` β `rspackOverride`](/docs/bundle#rspackoverride).#### `enableCaching?`diff --git a/packages/docs/docs/legacy-babel-loader.mdx b/packages/docs/docs/legacy-babel-loader.mdxindex b6f2eb46f2..91598d2cb2 100644--- a/packages/docs/docs/legacy-babel-loader.mdx+++ b/packages/docs/docs/legacy-babel-loader.mdx@@ -10,7 +10,7 @@ import TabItem from '@theme/TabItem';In Remotion 2.0, the traditional transpilation of Javascript and Typescript using the `babel-loader` has been replaced by the faster `esbuild-loader` by default.-If you for some reason need to go back to the previous behavior, you may [override the Webpack configuration](/docs/webpack). Remember that overriding the Webpack configuration works reducer-style, where you get the default configuration in a function argument and you return the modified version of your config.+If you for some reason need to go back to the previous behavior, you may [override the Webpack configuration](/docs/bundlers). Remember that overriding the Webpack configuration works reducer-style, where you get the default configuration in a function argument and you return the modified version of your config.We provide a compatibility package `@remotion/babel-loader` that you can install into your Remotion project and use the function `replaceLoadersWithBabel()` to swap out the ESBuild loader with the old Babel one that was in Remotion 1.0@@ -82,4 +82,4 @@ await bundle({## See also-- [Custom Webpack config](/docs/webpack)+- [Custom Webpack config](/docs/bundlers)diff --git a/packages/docs/docs/miscellaneous/ts-aliases.mdx b/packages/docs/docs/miscellaneous/ts-aliases.mdxindex 859994a671..7835e38b18 100644--- a/packages/docs/docs/miscellaneous/ts-aliases.mdx+++ b/packages/docs/docs/miscellaneous/ts-aliases.mdx@@ -7,7 +7,7 @@ crumb: 'How to'---Typescript aliases are not supported by default, since the ESBuild Webpack loader we have does not support them.-You can however patch the [Webpack config](/docs/webpack) to make them resolve.+You can however patch the [Webpack config](/docs/bundlers) to make them resolve.Assuming you have a file:@@ -81,4 +81,4 @@ We recommend that you don't use TypeScript aliases.## See also-- [Overriding webpack config](/docs/webpack)+- [Overriding webpack config](/docs/bundlers)diff --git a/packages/docs/docs/overwriting-webpack-config.mdx b/packages/docs/docs/overwriting-webpack-config.mdxindex ca778b5531..ccb962f5b3 100644--- a/packages/docs/docs/overwriting-webpack-config.mdx+++ b/packages/docs/docs/overwriting-webpack-config.mdx@@ -1,18 +1,73 @@---image: /generated/articles-docs-overwriting-webpack-config.pngid: webpack-title: Custom Webpack config+slug: /bundlers+title: Webpack and Rspackcrumb: 'How To'----import Tabs from '@theme/Tabs';-import TabItem from '@theme/TabItem';+Remotion bundles your project before opening the Studio or rendering media. It supports [Webpack](https://webpack.js.org/) and [Rspack](https://rspack.dev/).-Remotion ships with [its own Webpack configuration](https://github.com/remotion-dev/remotion/blob/main/packages/bundler/src/webpack-config.ts).+## Bundler roadmap-You can override it reducer-style by creating a function that takes the previous Webpack configuration and returns the next one.+Remotion used Webpack exclusively until experimental Rspack support was added in v4.0.426. Webpack remains the default bundler.-## When rendering using the command line+Rspack is intended to replace Webpack:++- Rspack will soon become the default for newly created projects.+- In a future major version of Remotion, Webpack support will be removed and Rspack will be the only bundler.++You can enable Rspack now to test your project before this transition.++## Enable Rspack<AvailableFrom v="4.0.426" />++Enable Rspack for CLI commands in [`remotion.config.ts`](/docs/config):++```ts twoslash title="remotion.config.ts"+import {Config} from '@remotion/cli/config';++Config.setExperimentalRspackEnabled(true);+```++To enable it for one command, use the `--experimental-rspack` flag:++```bash+npx remotion studio --experimental-rspack+```++The flag is also available for other commands that bundle your project, such as [`render`](/docs/cli/render), [`still`](/docs/cli/still), and [`bundle`](/docs/cli/bundle).++When using the Node.js [`bundle()`](/docs/bundle) API, set `rspack` to `true`:++```ts twoslash title="bundle.ts"+// @target: esnext+import {bundle} from '@remotion/bundler';++await bundle({+ entryPoint: require.resolve('./src/index.ts'),+ rspack: true,+});+```++The [`deploySite()`](/docs/lambda/deploysite#rspack) options for Lambda and [Cloud Run](/docs/cloudrun/deploysite#rspack) have the same `rspack` setting.++## Override the bundler configuration++Remotion provides three config file APIs:++| API | When it runs |+| ---------------------------------------------------------------------- | -------------------------------------------------------------- |+| [`Config.overrideBundlerConfig()`](/docs/config#overridebundlerconfig) | With either selected bundler. Runs first. |+| [`Config.overrideWebpackConfig()`](/docs/config#overridewebpackconfig) | Only when Webpack is selected. Runs after the shared override. |+| [`Config.overrideRspackConfig()`](/docs/config#overriderspackconfig) | Only when Rspack is selected. Runs after the shared override. |++You can call each override API more than once. Overrides of the same type run in registration order.++Only use [`Config.overrideBundlerConfig()`](/docs/config#overridebundlerconfig) for changes that are compatible with both bundlers. Webpack and Rspack plugins are not interchangeable.++Remotion ships with its own [Webpack configuration](https://github.com/remotion-dev/remotion/blob/main/packages/bundler/src/webpack-config.ts) and [Rspack configuration](https://github.com/remotion-dev/remotion/blob/main/packages/bundler/src/rspack-config.ts). Each override receives the previous configuration and returns the next one.++## Webpack overrides in `remotion.config.ts`In your [`remotion.config.ts`](/docs/config) file, you can call [`Config.overrideWebpackConfig()`](/docs/config#overridewebpackconfig) from `@remotion/cli/config`.@@ -55,9 +110,26 @@ Config.overrideWebpackConfig((config) => {Using the reducer pattern will help with type safety, give you auto-complete, ensure forwards-compatibility and keep it completely flexible - you can override just one property or pass in a completely new Webpack configuration.:::+## Rspack overrides in `remotion.config.ts`<AvailableFrom v="4.0.498" />++Use `Config.overrideRspackConfig()` when [Rspack is enabled](/docs/config#setexperimentalrspackenabled):++```ts twoslash title="remotion.config.ts"+import {Config} from '@remotion/cli/config';++Config.overrideRspackConfig((currentConfiguration) => {+ return {+ ...currentConfiguration,+ // Rspack-specific configuration+ };+});+```+## When using `bundle()` and `deploySite()`-When using the Node.JS APIs - [`bundle()`](/docs/bundle) for SSR or [`deploySite()`](/docs/lambda/deploysite) for Lambda, you also need to provide the Webpack override, since the Node.JS APIs do not read from the config file. We recommend you put the webpack override in a separate file so you can read it from both the command line and your Node.JS script.+Node.js APIs do not read `remotion.config.ts`. Pass the overrides directly to [`bundle()`](/docs/bundle) or [`deploySite()`](/docs/lambda/deploysite). Put an override in a separate file to import it from both `remotion.config.ts` and your Node.js script.++For Rspack, pass `rspackOverride`. Pass portable changes as `bundlerOverride`.```ts twoslash title="src/webpack-override.ts"import {WebpackOverrideFn} from '@remotion/bundler';@@ -123,7 +195,7 @@ await deploySite({});```-## Multiple Webpack overrides+## Multiple overridesIf you have multiple overrides, you should curry them:diff --git a/packages/docs/docs/player/player-integration.mdx b/packages/docs/docs/player/player-integration.mdxindex 18c773e8a1..339d43aeef 100644--- a/packages/docs/docs/player/player-integration.mdx+++ b/packages/docs/docs/player/player-integration.mdx@@ -11,7 +11,7 @@ import TabItem from '@theme/TabItem';If you are using the player, a common desire is to share the code with your Remotion Studio and/or server-side rendering. With the correct setup, you can write the component once and use it for previewing, displaying and rendering.:::note-Remotion and your React app use a different Webpack config. Therefore, if you want to override your [Webpack configuration](/docs/webpack), you need to override both the Remotion one and the React app one.+Remotion and your React app use different bundler configurations. Therefore, if you want to override your [bundler configuration](/docs/bundlers), you need to override both the Remotion one and the React app one.:::## Templatediff --git a/packages/docs/docs/skia/skia.mdx b/packages/docs/docs/skia/skia.mdxindex 04714c67c6..1a1f842f96 100644--- a/packages/docs/docs/skia/skia.mdx+++ b/packages/docs/docs/skia/skia.mdx@@ -28,7 +28,7 @@ Also update **all the other Remotion packages** to have the same version: `remotMake sure no package version number has a `^` character in front of it as it can lead to a version conflict.:::-[Override the Webpack config](/docs/webpack) by using [`enableSkia()`](/docs/skia/enable-skia).+[Override the bundler config](/docs/bundlers) by using [`enableSkia()`](/docs/skia/enable-skia).```ts twoslash title="remotion.config.ts"import {Config} from '@remotion/cli/config';diff --git a/packages/docs/docs/tailwind-v4/overview.mdx b/packages/docs/docs/tailwind-v4/overview.mdxindex cec3507c24..9528b7275c 100644--- a/packages/docs/docs/tailwind-v4/overview.mdx+++ b/packages/docs/docs/tailwind-v4/overview.mdx@@ -20,7 +20,7 @@ Install `@remotion/tailwind-v4` as well as TailwindCSS dependencies.<br />-[Override the Webpack config](/docs/webpack) by using [`enableTailwind()`](/docs/tailwind/enable-tailwind).+[Override the bundler config](/docs/bundlers) by using [`enableTailwind()`](/docs/tailwind/enable-tailwind).```ts twoslash title="remotion.config.ts"import {Config} from '@remotion/cli/config';diff --git a/packages/docs/docs/tailwind.mdx b/packages/docs/docs/tailwind.mdxindex 3abc09c40b..c914201700 100644--- a/packages/docs/docs/tailwind.mdx+++ b/packages/docs/docs/tailwind.mdx@@ -112,7 +112,7 @@ Config.overrideWebpackConfig((currentConfiguration) => {});```-3. If you use the [`bundle()` or `deploySite()` Node.JS API, add the Webpack override to it as well](/docs/webpack#when-using-bundle-and-deploysite).+3. If you use the [`bundle()` or `deploySite()` Node.JS API, add the Webpack override to it as well](/docs/bundlers#when-using-bundle-and-deploysite).4. Create a file `src/index.css` with the following content:@@ -199,7 +199,7 @@ Config.overrideWebpackConfig((currentConfiguration) => {Prior to `v3.3.39`, the option was called `Config.Bundling.overrideWebpackConfig()`.:::-3. If you use the [`bundle()` or `deploySite()` Node.JS API, add the Webpack override to it as well](/docs/webpack#when-using-bundle-and-deploysite).+3. If you use the [`bundle()` or `deploySite()` Node.JS API, add the Webpack override to it as well](/docs/bundlers#when-using-bundle-and-deploysite).4. Create a file `src/style.css` with the following content:diff --git a/packages/docs/docs/tailwind/overview.mdx b/packages/docs/docs/tailwind/overview.mdxindex 66d9959a56..53cebf337c 100644--- a/packages/docs/docs/tailwind/overview.mdx+++ b/packages/docs/docs/tailwind/overview.mdx@@ -25,7 +25,7 @@ Install `@remotion/tailwind` as well as TailwindCSS dependencies.<br />-[Override the Webpack config](/docs/webpack) by using [`enableTailwind()`](/docs/tailwind/enable-tailwind).+[Override the bundler config](/docs/bundlers) by using [`enableTailwind()`](/docs/tailwind/enable-tailwind).```ts twoslash title="remotion.config.ts"import {Config} from '@remotion/cli/config';diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 236b9de62f..db037e071c 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -4897,12 +4897,12 @@ export const articles = [},{id: 'webpack',- title: 'Custom Webpack config',+ title: 'Webpack and Rspack',relativePath: 'docs/overwriting-webpack-config.mdx',compId: 'articles-docs-overwriting-webpack-config',crumb: 'How To',noAi: false,- slug: 'webpack',+ slug: 'bundlers',},{id: 'parameterized-rendering',diff --git a/packages/docs/static/generated/articles-docs-bundle.png b/packages/docs/static/generated/articles-docs-bundle.pngindex 1e610ae14c..6f401d8ae9 100644Binary files a/packages/docs/static/generated/articles-docs-bundle.png and b/packages/docs/static/generated/articles-docs-bundle.png differdiff --git a/packages/docs/static/generated/articles-docs-cloudrun-deploysite.png b/packages/docs/static/generated/articles-docs-cloudrun-deploysite.pngindex 8a1365b6a4..cc5718c3d8 100644Binary files a/packages/docs/static/generated/articles-docs-cloudrun-deploysite.png and b/packages/docs/static/generated/articles-docs-cloudrun-deploysite.png differdiff --git a/packages/docs/static/generated/articles-docs-config.png b/packages/docs/static/generated/articles-docs-config.pngindex e48dcbfafd..7a7985e7bb 100644Binary files a/packages/docs/static/generated/articles-docs-config.png and b/packages/docs/static/generated/articles-docs-config.png differdiff --git a/packages/docs/static/generated/articles-docs-lambda-deploysite.png b/packages/docs/static/generated/articles-docs-lambda-deploysite.pngindex 43241367f8..52f5b3c693 100644Binary files a/packages/docs/static/generated/articles-docs-lambda-deploysite.png and b/packages/docs/static/generated/articles-docs-lambda-deploysite.png differdiff --git a/packages/docs/static/generated/articles-docs-overwriting-webpack-config.png b/packages/docs/static/generated/articles-docs-overwriting-webpack-config.pngindex e1f9348a64..bd6d423c7b 100644Binary files a/packages/docs/static/generated/articles-docs-overwriting-webpack-config.png and b/packages/docs/static/generated/articles-docs-overwriting-webpack-config.png differdiff --git a/packages/docs/vercel.ts b/packages/docs/vercel.tsindex 2c429aaa27..db2ab94465 100644--- a/packages/docs/vercel.ts+++ b/packages/docs/vercel.ts@@ -104,6 +104,7 @@ export const config: VercelConfig = {'/docs/renderer/get-compositions',{permanent: true},),+ routes.redirect('/docs/webpack', '/docs/bundlers', {permanent: true}),routes.redirect('/docs/stitch-frames-to-video','/docs/renderer/stitch-frames-to-video',diff --git a/packages/lambda/src/api/deploy-site.ts b/packages/lambda/src/api/deploy-site.tsindex d7bc33095d..0ac42530ed 100644--- a/packages/lambda/src/api/deploy-site.ts+++ b/packages/lambda/src/api/deploy-site.ts@@ -1,5 +1,10 @@import fs from 'node:fs';-import {type GitSource, type WebpackOverrideFn} from '@remotion/bundler';+import {+ type BundlerOverrideFn,+ type GitSource,+ type RspackOverrideFn,+ type WebpackOverrideFn,+} from '@remotion/bundler';import type {AwsRegion, RequestHandler} from '@remotion/lambda-client';import {LambdaClientInternals, type AwsProvider} from '@remotion/lambda-client';import {getSitesKey} from '@remotion/lambda-client/constants';@@ -31,6 +36,8 @@ type OptionalParameters = {onBundleProgress?: (progress: number) => void;onUploadProgress?: (upload: UploadDirProgress) => void;onDiffingProgress?: (bytes: number, done: boolean) => void;+ bundlerOverride?: BundlerOverrideFn;+ rspackOverride?: RspackOverrideFn;webpackOverride?: WebpackOverrideFn;ignoreRegisterRootWarning?: boolean;enableCaching?: boolean;@@ -85,6 +92,8 @@ const mandatoryDeploySite = async ({getBundle: async () => {generatedBundleDir = await fullClientSpecifics.bundleSite({publicPath: `/${getSitesKey(siteName)}/`,+ bundlerOverride: options.bundlerOverride ?? ((f) => f),+ rspackOverride: options.rspackOverride ?? ((f) => f),webpackOverride: options.webpackOverride ?? ((f) => f),enableCaching: options.enableCaching ?? true,publicDir: options.publicDir ?? null,diff --git a/packages/lambda/src/cli/commands/sites/create.ts b/packages/lambda/src/cli/commands/sites/create.tsindex 41e50cfd1f..25592edad9 100644--- a/packages/lambda/src/cli/commands/sites/create.ts+++ b/packages/lambda/src/cli/commands/sites/create.ts@@ -219,6 +219,8 @@ export const sitesCreateSubcommand = async (enableCaching: BrowserSafeApis.options.bundleCacheOption.getValue({commandLine: CliInternals.parsedCli,}).value,+ bundlerOverride: ConfigInternals.getBundlerOverrideFn(),+ rspackOverride: ConfigInternals.getRspackOverrideFn(),webpackOverride: ConfigInternals.getWebpackOverrideFn() ?? ((f) => f),bypassBucketNameValidation: Boolean(parsedLambdaCli['force-bucket-name']),askAIEnabled,diff --git a/packages/studio-server/src/preview-server/start-server.ts b/packages/studio-server/src/preview-server/start-server.tsindex f49e71ecc0..49557273d0 100644--- a/packages/studio-server/src/preview-server/start-server.ts+++ b/packages/studio-server/src/preview-server/start-server.ts@@ -1,6 +1,10 @@import type {IncomingMessage} from 'node:http';import http from 'node:http';-import type {WebpackOverrideFn} from '@remotion/bundler';+import type {+ BundlerOverrideFn,+ RspackOverrideFn,+ WebpackOverrideFn,+} from '@remotion/bundler';import {BundlerInternals,WatchIgnoreNextChangePlugin,@@ -40,6 +44,8 @@ export type StartServerResult =export const startServer = async (options: {entry: string;userDefinedComponent: string;+ bundlerOverride: BundlerOverrideFn;+ rspackOverride: RspackOverrideFn;webpackOverride: WebpackOverrideFn;getCurrentInputProps: () => object;getEnvVariables: () => Record<string, string>;@@ -97,6 +103,8 @@ export const startServer = async (options: {userDefinedComponent: options.userDefinedComponent,outDir: null,environment: 'development' as const,+ bundlerOverride: options.bundlerOverride,+ rspackOverride: options.rspackOverride,webpackOverride: options?.webpackOverride,remotionRoot: options.remotionRoot,poll: options.poll,diff --git a/packages/studio-server/src/start-studio.ts b/packages/studio-server/src/start-studio.tsindex f0af619c87..bafa97cd3b 100644--- a/packages/studio-server/src/start-studio.ts+++ b/packages/studio-server/src/start-studio.ts@@ -1,7 +1,11 @@import crypto from 'node:crypto';import {existsSync} from 'node:fs';import path from 'node:path';-import type {WebpackOverrideFn} from '@remotion/bundler';+import type {+ BundlerOverrideFn,+ RspackOverrideFn,+ WebpackOverrideFn,+} from '@remotion/bundler';import type {LogLevel} from '@remotion/renderer';import {RenderInternals} from '@remotion/renderer';import type {@@ -39,6 +43,8 @@ export const startStudio = async ({desiredPort,remotionRoot,relativePublicDir,+ bundlerOverride,+ rspackOverride,webpackOverride,poll,getRenderDefaults,@@ -67,6 +73,8 @@ export const startStudio = async ({desiredPort: number | null;remotionRoot: string;relativePublicDir: string | null;+ bundlerOverride: BundlerOverrideFn;+ rspackOverride: RspackOverrideFn;webpackOverride: WebpackOverrideFn;poll: number | null;getRenderDefaults: () => RenderDefaults;@@ -140,6 +148,8 @@ export const startStudio = async ({port: desiredPort,remotionRoot,publicDir,+ bundlerOverride,+ rspackOverride,webpackOverride,poll,staticHash,diff --git a/packages/tailwind-v4/src/enable.ts b/packages/tailwind-v4/src/enable.tsindex c4165e5876..35122d7905 100644--- a/packages/tailwind-v4/src/enable.ts+++ b/packages/tailwind-v4/src/enable.ts@@ -1,12 +1,12 @@-import type {WebpackConfiguration} from '@remotion/bundler';+import type {BundlerConfiguration} from '@remotion/bundler';/**- * @description A function that modifies the default Webpack configuration to make the necessary changes to support Tailwind.+ * @description A function that modifies the default bundler configuration to make the necessary changes to support Tailwind.* @see [Documentation](https://www.remotion.dev/docs/tailwind-v4/enable-tailwind)*/-export const enableTailwind: (- currentConfiguration: WebpackConfiguration,-) => WebpackConfiguration = (currentConfiguration) => {+export const enableTailwind = <Configuration extends BundlerConfiguration>(+ currentConfiguration: Configuration,+): Configuration => {return {...currentConfiguration,module: {diff --git a/packages/template-skia/README.md b/packages/template-skia/README.mdindex e1e70e37f3..bc7aa3f1c1 100644--- a/packages/template-skia/README.md+++ b/packages/template-skia/README.md@@ -39,7 +39,7 @@ npx remotion upgrade## Using server-side rendering-This template uses a [custom Webpack override](https://www.remotion.dev/docs/webpack). If you are using server-side rendering, you need to import `enableSkia` from `@remotion/skia/enable` and pass it to [`bundle()`](https://www.remotion.dev/docs/bundle) (if using SSR) and [`deploySite()`](https://www.remotion.dev/docs/lambda/deploysite) (if using Lambda):+This template uses a [custom Webpack override](https://www.remotion.dev/docs/bundlers). If you are using server-side rendering, you need to import `enableSkia` from `@remotion/skia/enable` and pass it to [`bundle()`](https://www.remotion.dev/docs/bundle) (if using SSR) and [`deploySite()`](https://www.remotion.dev/docs/lambda/deploysite) (if using Lambda):```tsbundle(entry, () => undefined, {