Skip to content

Commit d3fd330

Browse files
authored
feat: using @next/rspack-core (#84221)
Use `@next/rspack-core` to replace `@rspack/core` in order to utilize the extended `NextExternalsPlugin` plugin. The purpose is to enhance Rspack's performance in Next.js.
1 parent 1e4ae2c commit d3fd330

File tree

5 files changed

+343
-11
lines changed

5 files changed

+343
-11
lines changed

packages/next-rspack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
},
88
"types": "index.d.ts",
99
"dependencies": {
10-
"@rspack/core": "1.5.0"
10+
"@next/rspack-core": "1.0.0"
1111
}
1212
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('@rspack/core')
1+
module.exports = require('@next/rspack-core')

packages/next/src/build/webpack-config.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import getWebpackBundler from '../shared/lib/get-webpack-bundler'
9797
import type { NextBuildContext } from './build-context'
9898
import type { RootParamsLoaderOpts } from './webpack/loaders/next-root-params-loader'
9999
import type { InvalidImportLoaderOpts } from './webpack/loaders/next-invalid-import-error-loader'
100+
import { defaultOverrides } from '../server/require-hook'
100101

101102
type ExcludesFalse = <T>(x: T | false) => x is T
102103
type ClientEntries = {
@@ -966,7 +967,8 @@ export default async function getBaseWebpackConfig(
966967
...(isNodeServer ? { externalsPresets: { node: true } } : {}),
967968
// @ts-ignore
968969
externals:
969-
isClient || isEdgeServer
970+
!isRspack &&
971+
(isClient || isEdgeServer
970972
? // make sure importing "next" is handled gracefully for client
971973
// bundles in case a user imported types and it wasn't removed
972974
// TODO: should we warn/error for this instead?
@@ -1038,7 +1040,7 @@ export default async function getBaseWebpackConfig(
10381040
})
10391041
}
10401042
),
1041-
],
1043+
]),
10421044

10431045
optimization: {
10441046
emitOnErrors: !dev,
@@ -2173,6 +2175,15 @@ export default async function getBaseWebpackConfig(
21732175
compilerType,
21742176
...config.experimental.slowModuleDetection!,
21752177
}),
2178+
isRspack &&
2179+
new (getRspackCore().NextExternalsPlugin)({
2180+
compilerType,
2181+
config,
2182+
optOutBundlingPackageRegex,
2183+
finalTranspilePackages,
2184+
dir,
2185+
defaultOverrides,
2186+
}),
21762187
].filter(Boolean as any as ExcludesFalse),
21772188
}
21782189

0 commit comments

Comments
 (0)