Skip to content

Commit

Permalink
Built-in swc loader plugin for additional bundler
Browse files Browse the repository at this point in the history
 (#76023)

Added support for a built-in SWC loader in Rspack configuration when `BUILTIN_SWC_LOADER` environment variable is set.

Ported from https://github.com/vercel/next.js/tree/wbinnssmith/try-ci-test, originally by @SyMind.
  • Loading branch information
wbinnssmith authored Feb 19, 2025
1 parent 1405eaf commit 13737cd
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,45 @@ export default async function getBaseWebpackConfig(
)
}

const useBuiltinSwcLoader = process.env.BUILTIN_SWC_LOADER
if (isRspack && useBuiltinSwcLoader) {
return {
loader: 'builtin:next-swc-loader',
options: {
isServer: isNodeOrEdgeCompilation,
rootDir: dir,
pagesDir,
appDir,
hasReactRefresh: dev && isClient,
transpilePackages: finalTranspilePackages,
supportedBrowsers,
swcCacheDir: path.join(
dir,
config?.distDir ?? '.next',
'cache',
'swc'
),
serverReferenceHashSalt: encryptionKey,

// rspack specific options
pnp: Boolean(process.versions.pnp),
optimizeServerReact: Boolean(config.experimental.optimizeServerReact),
modularizeImports: config.modularizeImports,
decorators: Boolean(
jsConfig?.compilerOptions?.experimentalDecorators
),
emitDecoratorMetadata: Boolean(
jsConfig?.compilerOptions?.emitDecoratorMetadata
),
regeneratorRuntimePath: require.resolve(
'next/dist/compiled/regenerator-runtime'
),

...extraOptions,
},
}
}

return {
loader: 'next-swc-loader',
options: {
Expand Down

0 comments on commit 13737cd

Please sign in to comment.