fix(faster): allow Rspack + babel-loader (#10617)
Some checks failed
Argos CI / take-screenshots (push) Has been cancelled
Build Hash Router / Build Hash Router (push) Has been cancelled
Canary Release / Publish Canary (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Continuous Releases / Continuous Releases (push) Has been cancelled
E2E Tests / E2E — Yarn v1 (18.0) (push) Has been cancelled
E2E Tests / E2E — Yarn v1 (20) (push) Has been cancelled
E2E Tests / E2E — Yarn v1 (22) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Has been cancelled
E2E Tests / E2E — npm (push) Has been cancelled
E2E Tests / E2E — pnpm (push) Has been cancelled

This commit is contained in:
Sébastien Lorber 2024-10-25 19:24:20 +02:00 committed by GitHub
parent 52e50d29bc
commit 34f9a36a9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<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 (
@ -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;