-
Notifications
You must be signed in to change notification settings - Fork 27.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update bundler for pre-bundling runtime #75294
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
const webpack = require('webpack') | ||
const webpack = require('@rspack/core') | ||
const path = require('path') | ||
const TerserPlugin = require('terser-webpack-plugin') | ||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer') | ||
const EvalSourceMapDevToolPlugin = require('./webpack-plugins/eval-source-map-dev-tool-plugin') | ||
const DevToolsIgnoreListPlugin = require('./webpack-plugins/devtools-ignore-list-plugin') | ||
|
||
function shouldIgnorePath(modulePath) { | ||
function shouldIgnorePath() { | ||
// For consumers, everything will be considered 3rd party dependency if they use | ||
// the bundles we produce here. | ||
// In other words, this is all library code and should therefore be ignored. | ||
|
@@ -130,6 +128,11 @@ const bundleTypes = { | |
module.exports = ({ dev, turbo, bundleType, experimental }) => { | ||
const externalHandler = ({ context, request, getResolve }, callback) => { | ||
;(async () => { | ||
if (request.match(/next[/\\]dist[/\\]compiled[/\\](babel|webpack)/)) { | ||
callback(null, 'commonjs ' + request) | ||
return | ||
} | ||
|
||
Comment on lines
+131
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect this is breaking Next.js with custom Babel configs:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that |
||
if (request.endsWith('.external')) { | ||
const resolve = getResolve() | ||
const resolved = await resolve(context, request) | ||
|
@@ -156,44 +159,23 @@ module.exports = ({ dev, turbo, bundleType, experimental }) => { | |
return { | ||
entry: bundleTypes[bundleType], | ||
target: 'node', | ||
mode: 'production', | ||
mode: dev ? 'development' : 'production', | ||
output: { | ||
path: path.join(__dirname, 'dist/compiled/next-server'), | ||
filename: `[name]${turbo ? '-turbo' : ''}${ | ||
experimental ? '-experimental' : '' | ||
}.runtime.${dev ? 'dev' : 'prod'}.js`, | ||
libraryTarget: 'commonjs2', | ||
}, | ||
devtool: process.env.NEXT_SERVER_EVAL_SOURCE_MAPS | ||
? // We'll use a fork in plugins | ||
false | ||
: 'source-map', | ||
devtool: 'source-map', | ||
optimization: { | ||
moduleIds: 'named', | ||
minimize: true, | ||
concatenateModules: true, | ||
minimizer: [ | ||
new TerserPlugin({ | ||
minify: TerserPlugin.swcMinify, | ||
terserOptions: { | ||
compress: { | ||
dead_code: true, | ||
// Zero means no limit. | ||
passes: 0, | ||
}, | ||
format: { | ||
preamble: '', | ||
}, | ||
mangle: | ||
dev && !process.env.NEXT_SERVER_EVAL_SOURCE_MAPS ? false : true, | ||
}, | ||
}), | ||
], | ||
minimizer: [new webpack.SwcJsMinimizerRspackPlugin()], | ||
}, | ||
plugins: [ | ||
process.env.NEXT_SERVER_EVAL_SOURCE_MAPS | ||
? new EvalSourceMapDevToolPlugin({ shouldIgnorePath }) | ||
: new DevToolsIgnoreListPlugin({ shouldIgnorePath }), | ||
new DevToolsIgnoreListPlugin({ shouldIgnorePath }), | ||
new webpack.DefinePlugin({ | ||
'typeof window': JSON.stringify('undefined'), | ||
'process.env.NEXT_MINIMAL': JSON.stringify('true'), | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fully removed in #75297