Skip to content

Commit 8eb9a1f

Browse files
committed
fix: Remove rspack imports and simplify webpack config
Remove all rspack-related imports and conditional code paths: - Remove getRspackCore and getRspackReactRefresh imports - Simplify getWebpackBundler to only return webpack - Remove rspack conditional branches for: - React refresh loaders and plugins - JS/CSS minimizers - Profiling plugins - CSS chunking plugins - CSS extract plugins - Source map dev tool plugins - Remove unused isRspack variable All code now uses webpack implementations directly without rspack alternatives.
1 parent ce499ba commit 8eb9a1f

File tree

5 files changed

+44
-116
lines changed

5 files changed

+44
-116
lines changed

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

Lines changed: 30 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ import {
9494
NEXT_PROJECT_ROOT,
9595
NEXT_PROJECT_ROOT_DIST_CLIENT,
9696
} from './next-dir-paths'
97-
import { getRspackCore, getRspackReactRefresh } from '../shared/lib/get-rspack'
98-
import { RspackProfilingPlugin } from './webpack/plugins/rspack-profiling-plugin'
9997
import getWebpackBundler from '../shared/lib/get-webpack-bundler'
10098
import type { NextBuildContext } from './build-context'
10199
import type { RootParamsLoaderOpts } from './webpack/loaders/next-root-params-loader'
@@ -177,9 +175,7 @@ const reactRefreshLoaderName =
177175
'next/dist/compiled/@next/react-refresh-utils/dist/loader'
178176

179177
function getReactRefreshLoader() {
180-
return process.env.NEXT_RSPACK
181-
? getRspackReactRefresh().loader
182-
: require.resolve(reactRefreshLoaderName)
178+
return require.resolve(reactRefreshLoaderName)
183179
}
184180

185181
export function attachReactRefresh(
@@ -697,11 +693,9 @@ export default async function getBaseWebpackConfig(
697693
'...',
698694
]
699695

700-
const reactRefreshEntry = isRspack
701-
? getRspackReactRefresh().entry
702-
: require.resolve(
703-
`next/dist/compiled/@next/react-refresh-utils/dist/runtime`
704-
)
696+
const reactRefreshEntry = require.resolve(
697+
`next/dist/compiled/@next/react-refresh-utils/dist/runtime`
698+
)
705699

706700
const clientEntries = isClient
707701
? ({
@@ -1230,61 +1224,32 @@ export default async function getBaseWebpackConfig(
12301224
(isNodeServer && config.experimental.serverMinification)),
12311225
minimizer: [
12321226
// Minify JavaScript
1233-
isRspack
1234-
? new (getRspackCore().SwcJsMinimizerRspackPlugin)({
1235-
// JS minimizer configuration
1236-
minimizerOptions: {
1237-
compress: {
1238-
inline: 2,
1239-
global_defs: {
1240-
'process.env.__NEXT_PRIVATE_MINIMIZE_MACRO_FALSE': false,
1241-
},
1242-
},
1243-
mangle: !noMangling && {
1244-
reserved: ['AbortSignal'],
1245-
disableCharFreq: !isClient,
1246-
},
1247-
},
1248-
})
1249-
: (compiler: webpack.Compiler) => {
1250-
// @ts-ignore No typings yet
1251-
const { MinifyPlugin } =
1252-
require('./webpack/plugins/minify-webpack-plugin/src') as typeof import('./webpack/plugins/minify-webpack-plugin/src')
1253-
new MinifyPlugin({
1254-
noMangling,
1255-
disableCharFreq: !isClient,
1256-
}).apply(compiler)
1257-
},
1227+
(compiler: webpack.Compiler) => {
1228+
// @ts-ignore No typings yet
1229+
const { MinifyPlugin } =
1230+
require('./webpack/plugins/minify-webpack-plugin/src') as typeof import('./webpack/plugins/minify-webpack-plugin/src')
1231+
new MinifyPlugin({
1232+
noMangling,
1233+
disableCharFreq: !isClient,
1234+
}).apply(compiler)
1235+
},
12581236
// Minify CSS
1259-
// By default, Rspack uses LightningCSS for CSS minification.
1260-
// Rspack uses css-minimizer-plugin by default for compatibility.
1261-
isRspack &&
1262-
(process.env.__NEXT_TEST_MODE
1263-
? config.experimental.useLightningcss
1264-
: config.experimental?.useLightningcss === undefined ||
1265-
config.experimental.useLightningcss)
1266-
? new (getRspackCore().LightningCssMinimizerRspackPlugin)({
1267-
// CSS minimizer configuration
1268-
minimizerOptions: {
1269-
targets: supportedBrowsers,
1237+
(compiler: webpack.Compiler) => {
1238+
const { CssMinimizerPlugin } =
1239+
require('./webpack/plugins/css-minimizer-plugin') as typeof import('./webpack/plugins/css-minimizer-plugin')
1240+
new CssMinimizerPlugin({
1241+
postcssOptions: {
1242+
map: {
1243+
// `inline: false` generates the source map in a separate file.
1244+
// Otherwise, the CSS file is needlessly large.
1245+
inline: false,
1246+
// `annotation: false` skips appending the `sourceMappingURL`
1247+
// to the end of the CSS file. Webpack already handles this.
1248+
annotation: false,
12701249
},
1271-
})
1272-
: (compiler: webpack.Compiler) => {
1273-
const { CssMinimizerPlugin } =
1274-
require('./webpack/plugins/css-minimizer-plugin') as typeof import('./webpack/plugins/css-minimizer-plugin')
1275-
new CssMinimizerPlugin({
1276-
postcssOptions: {
1277-
map: {
1278-
// `inline: false` generates the source map in a separate file.
1279-
// Otherwise, the CSS file is needlessly large.
1280-
inline: false,
1281-
// `annotation: false` skips appending the `sourceMappingURL`
1282-
// to the end of the CSS file. Webpack already handles this.
1283-
annotation: false,
1284-
},
1285-
},
1286-
}).apply(compiler)
12871250
},
1251+
}).apply(compiler)
1252+
},
12881253
],
12891254
},
12901255
context: dir,
@@ -1983,16 +1948,7 @@ export default async function getBaseWebpackConfig(
19831948
}
19841949
),
19851950
dev && new MemoryWithGcCachePlugin({ maxGenerations: 5 }),
1986-
dev &&
1987-
isClient &&
1988-
(isRspack
1989-
? // eslint-disable-next-line
1990-
new (getRspackReactRefresh() as any)({
1991-
injectLoader: false,
1992-
injectEntry: false,
1993-
overlay: false,
1994-
})
1995-
: new ReactRefreshWebpackPlugin(webpack)),
1951+
dev && isClient && new ReactRefreshWebpackPlugin(webpack),
19961952
// Makes sure `Buffer` and `process` are polyfilled in client and flight bundles (same behavior as webpack 4)
19971953
(isClient || isEdgeServer) &&
19981954
new bundler.ProvidePlugin({
@@ -2110,9 +2066,7 @@ export default async function getBaseWebpackConfig(
21102066
appDirEnabled: hasAppDir,
21112067
clientRouterFilters,
21122068
}),
2113-
isRspack
2114-
? new RspackProfilingPlugin({ runWebpackSpan })
2115-
: new ProfilingPlugin({ runWebpackSpan, rootDir: dir }),
2069+
new ProfilingPlugin({ runWebpackSpan, rootDir: dir }),
21162070
new WellKnownErrorsPlugin(),
21172071
isClient &&
21182072
new CopyFilePlugin({
@@ -2165,14 +2119,7 @@ export default async function getBaseWebpackConfig(
21652119
!dev &&
21662120
isClient &&
21672121
config.experimental.cssChunking &&
2168-
(isRspack
2169-
? new (getRspackCore().experiments.CssChunkingPlugin)({
2170-
strict: config.experimental.cssChunking === 'strict',
2171-
nextjs: true,
2172-
})
2173-
: new CssChunkingPlugin(
2174-
config.experimental.cssChunking === 'strict'
2175-
)),
2122+
new CssChunkingPlugin(config.experimental.cssChunking === 'strict'),
21762123
telemetryPlugin,
21772124
!dev &&
21782125
isNodeServer &&

packages/next/src/build/webpack/config/blocks/base.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { COMPILER_NAMES } from '../../../../shared/lib/constants'
44
import type { ConfigurationContext } from '../utils'
55
import DevToolsIgnorePlugin from '../../plugins/devtools-ignore-list-plugin'
66
import EvalSourceMapDevToolPlugin from '../../plugins/eval-source-map-dev-tool-plugin'
7-
import { getRspackCore } from '../../../../shared/lib/get-rspack'
87

98
function shouldIgnorePath(modulePath: string): boolean {
109
return (
@@ -67,20 +66,12 @@ export const base = curry(function base(
6766
} else if (config.devtool === 'eval-source-map') {
6867
// We're using a fork of `eval-source-map`
6968
config.devtool = false
70-
if (process.env.NEXT_RSPACK) {
71-
config.plugins.push(
72-
new (getRspackCore().EvalSourceMapDevToolPlugin)({
73-
moduleFilenameTemplate: config.output?.devtoolModuleFilenameTemplate,
74-
})
75-
)
76-
} else {
77-
config.plugins.push(
78-
new EvalSourceMapDevToolPlugin({
79-
moduleFilenameTemplate: config.output?.devtoolModuleFilenameTemplate,
80-
shouldIgnorePath,
81-
})
82-
)
83-
}
69+
config.plugins.push(
70+
new EvalSourceMapDevToolPlugin({
71+
moduleFilenameTemplate: config.output?.devtoolModuleFilenameTemplate,
72+
shouldIgnorePath,
73+
})
74+
)
8475
}
8576

8677
// TODO: add codemod for "Should not import the named export" with JSON files

packages/next/src/build/webpack/config/blocks/css/index.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
import { getPostCssPlugins } from './plugins'
1515
import { nonNullable } from '../../../../../lib/non-nullable'
1616
import { WEBPACK_LAYERS } from '../../../../../lib/constants'
17-
import { getRspackCore } from '../../../../../shared/lib/get-rspack'
1817

1918
// RegExps for all Style Sheet variants
2019
export const regexLikeCss = /\.(css|scss|sass)$/
@@ -148,7 +147,6 @@ export const css = curry(async function css(
148147
ctx: ConfigurationContext,
149148
config: webpack.Configuration
150149
) {
151-
const isRspack = Boolean(process.env.NEXT_RSPACK)
152150
const {
153151
prependData: sassPrependData,
154152
additionalData: sassAdditionalData,
@@ -594,11 +592,9 @@ export const css = curry(async function css(
594592
// Enable full mini-css-extract-plugin hmr for prod mode pages or app dir
595593
if (ctx.isClient && (ctx.isProduction || ctx.hasAppDir)) {
596594
// Extract CSS as CSS file(s) in the client-side production bundle.
597-
const MiniCssExtractPlugin = isRspack
598-
? getRspackCore().CssExtractRspackPlugin
599-
: (
600-
require('../../../plugins/mini-css-extract-plugin') as typeof import('../../../plugins/mini-css-extract-plugin')
601-
).default
595+
const MiniCssExtractPlugin = (
596+
require('../../../plugins/mini-css-extract-plugin') as typeof import('../../../plugins/mini-css-extract-plugin')
597+
).default
602598

603599
fns.push(
604600
plugin(

packages/next/src/build/webpack/config/blocks/css/loaders/client.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { webpack } from 'next/dist/compiled/webpack/webpack'
2-
import { getRspackCore } from '../../../../../../shared/lib/get-rspack'
32

43
export function getClientStyleLoader({
54
hasAppDir,
@@ -12,7 +11,6 @@ export function getClientStyleLoader({
1211
isDevelopment: boolean
1312
assetPrefix: string
1413
}): webpack.RuleSetUseItem {
15-
const isRspack = Boolean(process.env.NEXT_RSPACK)
1614
const shouldEnableApp = typeof isAppDir === 'boolean' ? isAppDir : hasAppDir
1715

1816
// Keep next-style-loader for development mode in `pages/`
@@ -43,11 +41,9 @@ export function getClientStyleLoader({
4341
}
4442
}
4543

46-
const MiniCssExtractPlugin = isRspack
47-
? getRspackCore().rspack.CssExtractRspackPlugin
48-
: (
49-
require('../../../../plugins/mini-css-extract-plugin') as typeof import('../../../../plugins/mini-css-extract-plugin')
50-
).default
44+
const MiniCssExtractPlugin = (
45+
require('../../../../plugins/mini-css-extract-plugin') as typeof import('../../../../plugins/mini-css-extract-plugin')
46+
).default
5147

5248
return {
5349
loader: MiniCssExtractPlugin.loader,
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { webpack } from 'next/dist/compiled/webpack/webpack'
2-
import { getRspackCore } from './get-rspack'
32

43
/**
5-
* Depending on if Rspack is active or not, returns the appropriate set of
6-
* webpack-compatible api.
4+
* Returns the webpack bundler.
75
*
86
* @returns webpack bundler
97
*/
108
export default function getWebpackBundler(): typeof webpack {
11-
return process.env.NEXT_RSPACK ? getRspackCore() : webpack
9+
return webpack
1210
}

0 commit comments

Comments
 (0)