@@ -9,6 +9,7 @@ import webpack from 'webpack';
99import { copyDir } from './copy-dir' ;
1010import { indexHtml } from './index-html' ;
1111import { readRecursively } from './read-recursively' ;
12+ import { rspackConfig } from './rspack-config' ;
1213import type { WebpackOverrideFn } from './webpack-config' ;
1314import { 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
5759export 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
103111type 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}
0 commit comments