From 34f9a36a9d717f4add306264de0d7f32271c2ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Fri, 25 Oct 2024 19:24:20 +0200 Subject: [PATCH] fix(faster): allow Rspack + babel-loader (#10617) --- .../docusaurus-bundler/src/loaders/jsLoader.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/docusaurus-bundler/src/loaders/jsLoader.ts b/packages/docusaurus-bundler/src/loaders/jsLoader.ts index b7ed1044751d..b6e0088ebd88 100644 --- a/packages/docusaurus-bundler/src/loaders/jsLoader.ts +++ b/packages/docusaurus-bundler/src/loaders/jsLoader.ts @@ -20,7 +20,7 @@ const BabelJsLoaderFactory: ConfigureWebpackUtils['getJSLoader'] = ({ }; }; -async function createSwcLoaderFactory(): Promise< +async function createSwcJsLoaderFactory(): Promise< ConfigureWebpackUtils['getJSLoader'] > { const loader = await importSwcLoader(); @@ -34,7 +34,7 @@ async function createSwcLoaderFactory(): Promise< } // Same as swcLoader, except we use the built-in SWC loader -async function createRspackLoaderFactory(): Promise< +async function createRspackSwcJsLoaderFactory(): Promise< ConfigureWebpackUtils['getJSLoader'] > { const loader = 'builtin:swc-loader'; @@ -62,14 +62,10 @@ export async function createJsLoaderFactory({ }): Promise { const currentBundler = await getCurrentBundler({siteConfig}); const isSWCLoader = siteConfig.future.experimental_faster.swcJsLoader; - if (currentBundler.name === 'rspack') { - if (!isSWCLoader) { - throw new Error( - 'When using Rspack bundler, it is required to enable swcJsLoader too', - ); - } - return createRspackLoaderFactory(); + return isSWCLoader + ? createRspackSwcJsLoaderFactory() + : BabelJsLoaderFactory; } const jsLoader = siteConfig.webpack?.jsLoader ?? 'babel'; if ( @@ -84,7 +80,7 @@ export async function createJsLoaderFactory({ return ({isServer}) => jsLoader(isServer); } if (siteConfig.future?.experimental_faster.swcJsLoader) { - return createSwcLoaderFactory(); + return createSwcJsLoaderFactory(); } if (jsLoader === 'babel') { return BabelJsLoaderFactory;