Skip to content

Commit

Permalink
allow Rspack + babel-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Oct 25, 2024
1 parent d723a1e commit eef3275
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 eef3275

Please sign in to comment.