Skip to content

Commit

Permalink
Don't mangle dev bundles, or if NEXT_SERVER_NO_MANGLE is set
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Jan 24, 2025
1 parent 974d5b5 commit df845a3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 231 deletions.
2 changes: 1 addition & 1 deletion contributing/core/vscode-debugger.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ To see the changes you make to the Next.js codebase during development, you can

When developing/debugging Next.js, you can set breakpoints anywhere in the `packages/next` source code that will stop the debugger at certain locations so you can examine the behavior. Read more about [breakpoints in the VS Code documentation](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_breakpoints).

To ensure that the original names are displayed in the "Variables" section, build the Next.js source code with `NEXT_SERVER_EVAL_SOURCE_MAPS=1`. This is automatically applied when using `pnpm dev`.
To ensure that the original names are displayed in the "Variables" section, build the Next.js source code with `NEXT_SERVER_NO_MANGLE=1`. This is automatically applied when using `pnpm dev`.
13 changes: 3 additions & 10 deletions packages/next/next_runtime.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const rspack = require('@rspack/core')
const path = require('path')
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() {
Expand Down Expand Up @@ -168,27 +167,21 @@ module.exports = ({ dev, turbo, bundleType, 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 rspack.SwcJsMinimizerRspackPlugin({
minimizerOptions: {
mangle: false,
mangle: dev || process.env.NEXT_SERVER_NO_MANGLE ? false : true,
},
}),
],
},
plugins: [
process.env.NEXT_SERVER_EVAL_SOURCE_MAPS
? new EvalSourceMapDevToolPlugin({ shouldIgnorePath })
: new DevToolsIgnoreListPlugin({ shouldIgnorePath }),

new DevToolsIgnoreListPlugin({ shouldIgnorePath }),
new rspack.DefinePlugin({
'typeof window': JSON.stringify('undefined'),
'process.env.NEXT_MINIMAL': JSON.stringify('true'),
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"next": "./dist/bin/next"
},
"scripts": {
"dev": "taskr",
"dev": "cross-env NEXT_SERVER_NO_MANGLE=1 taskr",
"release": "taskr release",
"build": "pnpm release",
"prepublishOnly": "cd ../../ && turbo run build",
Expand Down
219 changes: 0 additions & 219 deletions packages/next/webpack-plugins/eval-source-map-dev-tool-plugin.js

This file was deleted.

0 comments on commit df845a3

Please sign in to comment.