Skip to content

Commit 506e5c0

Browse files
JonnyBurgerclaude
andcommitted
@remotion/bundler: Add --rspack flag for optional Rspack bundling
Add Rspack as an optional alternative bundler controlled by `--rspack` flag (e.g., `npx remotion studio --rspack`). Webpack remains the default. - Add `@rspack/core` and `@rspack/plugin-react-refresh` dependencies - Create `rspack-config.ts` paralleling webpack-config.ts with SWC loader - Define `--rspack` CLI option and thread it through studio/bundle paths - Branch compiler creation in start-server.ts and bundle.ts based on flag Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f80bfd0 commit 506e5c0

File tree

16 files changed

+405
-22
lines changed

16 files changed

+405
-22
lines changed

bun.lock

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bundler/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"author": "Jonny Burger <jonny@remotion.dev>",
2020
"license": "SEE LICENSE IN LICENSE.md",
2121
"dependencies": {
22+
"@rspack/core": "1.7.6",
23+
"@rspack/plugin-react-refresh": "1.6.1",
2224
"css-loader": "5.2.7",
2325
"esbuild": "0.25.0",
2426
"react-refresh": "0.9.0",

packages/bundler/src/bundle.ts

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import webpack from 'webpack';
99
import {copyDir} from './copy-dir';
1010
import {indexHtml} from './index-html';
1111
import {readRecursively} from './read-recursively';
12+
import {rspackConfig} from './rspack-config';
1213
import type {WebpackOverrideFn} from './webpack-config';
1314
import {webpackConfig} from './webpack-config';
1415

@@ -52,6 +53,7 @@ export type MandatoryLegacyBundleOptions = {
5253
onSymlinkDetected: (path: string) => void;
5354
keyboardShortcutsEnabled: boolean;
5455
askAIEnabled: boolean;
56+
rspack: boolean;
5557
};
5658

5759
export type LegacyBundleOptions = Partial<MandatoryLegacyBundleOptions>;
@@ -75,7 +77,7 @@ export const getConfig = ({
7577
onProgress?: (progress: number) => void;
7678
options?: LegacyBundleOptions;
7779
}) => {
78-
return webpackConfig({
80+
const configArgs = {
7981
entry: path.join(
8082
require.resolve('@remotion/studio/renderEntry'),
8183
'..',
@@ -84,9 +86,9 @@ export const getConfig = ({
8486
),
8587
userDefinedComponent: entryPoint,
8688
outDir,
87-
environment: 'production',
89+
environment: 'production' as const,
8890
webpackOverride: options?.webpackOverride ?? ((f) => f),
89-
onProgress: (p) => {
91+
onProgress: (p: number) => {
9092
onProgress?.(p);
9193
},
9294
enableCaching: options?.enableCaching ?? true,
@@ -97,7 +99,13 @@ export const getConfig = ({
9799
poll: null,
98100
experimentalClientSideRenderingEnabled,
99101
askAIEnabled: options?.askAIEnabled ?? true,
100-
});
102+
};
103+
104+
if (options?.rspack) {
105+
return rspackConfig(configArgs);
106+
}
107+
108+
return webpackConfig(configArgs);
101109
};
102110

103111
type NewBundleOptions = {
@@ -229,20 +237,59 @@ export const internalBundle = async (
229237
actualArgs.experimentalClientSideRenderingEnabled,
230238
});
231239

232-
const output = (await promisified([config])) as
233-
| webpack.MultiStats
234-
| undefined;
235-
if (isMainThread) {
236-
process.chdir(currentCwd);
237-
}
240+
if (actualArgs.rspack) {
241+
const {rspack: rspackFn} = require('@rspack/core');
242+
const rspackCompiler = rspackFn(config);
243+
const rspackOutput = await new Promise<{
244+
toJson: (opts: unknown) => {
245+
errors?: Array<{message: string; details: string}>;
246+
};
247+
}>((resolve, reject) => {
248+
rspackCompiler.run(
249+
(
250+
err: Error | null,
251+
stats: {
252+
toJson: (opts: unknown) => {
253+
errors?: Array<{message: string; details: string}>;
254+
};
255+
},
256+
) => {
257+
if (err) {
258+
reject(err);
259+
return;
260+
}
261+
262+
rspackCompiler.close(() => {
263+
resolve(stats);
264+
});
265+
},
266+
);
267+
});
238268

239-
if (!output) {
240-
throw new Error('Expected webpack output');
241-
}
269+
if (isMainThread) {
270+
process.chdir(currentCwd);
271+
}
272+
273+
const {errors} = rspackOutput.toJson({});
274+
if (errors !== undefined && errors.length > 0) {
275+
throw new Error(errors[0].message + '\n' + errors[0].details);
276+
}
277+
} else {
278+
const output = (await promisified([config as webpack.Configuration])) as
279+
| webpack.MultiStats
280+
| undefined;
281+
if (isMainThread) {
282+
process.chdir(currentCwd);
283+
}
284+
285+
if (!output) {
286+
throw new Error('Expected webpack output');
287+
}
242288

243-
const {errors} = output.toJson();
244-
if (errors !== undefined && errors.length > 0) {
245-
throw new Error(errors[0].message + '\n' + errors[0].details);
289+
const {errors} = output.toJson();
290+
if (errors !== undefined && errors.length > 0) {
291+
throw new Error(errors[0].message + '\n' + errors[0].details);
292+
}
246293
}
247294

248295
const publicPath = actualArgs?.publicPath ?? '/';
@@ -368,6 +415,7 @@ export async function bundle(...args: Arguments): Promise<string> {
368415
renderDefaults: actualArgs.renderDefaults ?? null,
369416
askAIEnabled: actualArgs.askAIEnabled ?? true,
370417
keyboardShortcutsEnabled: actualArgs.keyboardShortcutsEnabled ?? true,
418+
rspack: actualArgs.rspack ?? false,
371419
});
372420
return result;
373421
}

packages/bundler/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {findClosestFolderWithItem, getConfig, internalBundle} from './bundle';
22
import {indexHtml} from './index-html';
33
import {readRecursively} from './read-recursively';
4+
import {createRspackCompiler, rspackConfig} from './rspack-config';
45
import {cacheExists, clearCache} from './webpack-cache';
56
import {webpackConfig} from './webpack-config';
67
import esbuild = require('esbuild');
@@ -9,6 +10,8 @@ import webpack = require('webpack');
910
export const BundlerInternals = {
1011
esbuild,
1112
webpackConfig,
13+
rspackConfig,
14+
createRspackCompiler,
1215
indexHtml,
1316
cacheExists,
1417
clearCache,

0 commit comments

Comments
 (0)