Skip to content

Commit

Permalink
fix(faster): allow Rspack + babel-loader (#10617)
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber authored Oct 25, 2024
1 parent 52e50d2 commit 34f9a36
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions packages/docusaurus-bundler/src/loaders/jsLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const BabelJsLoaderFactory: ConfigureWebpackUtils['getJSLoader'] = ({
};
};

async function createSwcLoaderFactory(): Promise<
async function createSwcJsLoaderFactory(): Promise<
ConfigureWebpackUtils['getJSLoader']
> {
const loader = await importSwcLoader();
Expand All @@ -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';
Expand Down Expand Up @@ -62,14 +62,10 @@ export async function createJsLoaderFactory({
}): Promise<ConfigureWebpackUtils['getJSLoader']> {
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 (
Expand All @@ -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;
Expand Down

0 comments on commit 34f9a36

Please sign in to comment.