Unverified Commit e4ceb139 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Enable Turbopack export name mangling by default for builds (#99362)

### What?

`experimental.turbopackMangleExportNames` is now on by default for
production builds (`next build`) in both stable and canary releases. It
stays off by default in development (`next dev`), and an explicit
`true`/`false` in `next.config` still wins in either mode.

### Why?

Mangling export names shortens the keys modules use to link to each
other, which reduces bundle size. Until now it was only on by default in
canary builds, because stable releases pinned it to `false`.

### How?

Turbopack already chooses the default from the build mode in
`NextConfig::turbopack_mangle_export_names`: if the option is unset,
it's enabled everywhere except development, and an explicit value
overrides that. The only thing keeping it off on stable was the JS
default config, which forced `false` when `isStableBuild()` was true.
That pin is removed, so the default stays unset on every release channel
and the Rust side decides from the build mode. There's no change to Rust
or to the mangling itself.

The JSDoc on the config type and the Turbopack config docs table now say
the default is `false` in dev and `true` for builds.

### Verification

- Prettier and ESLint pass on the changed files.
- `pnpm --filter=next types`: only 3 `TS2307` errors, all for missing
generated `dist` modules (`@next/font`, `@vercel/og`) in an
unbootstrapped checkout. The same errors show up without this change,
and none are in `config-shared.ts`.
- Not run: a bootstrapped integration build. CI covers the build-mode
behavior end to end.

<!-- NEXT_JS_LLM -->


<!-- fleet dfbd6860-64e0-4a98-ac6f-220e8131fee2 -->

---------
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent a3526b8e
...@@ -1224,7 +1224,8 @@ pub struct ExperimentalConfig { ...@@ -1224,7 +1224,8 @@ pub struct ExperimentalConfig {
turbopack_infer_module_side_effects: Option<bool>, turbopack_infer_module_side_effects: Option<bool>,
/// Enable tree shaking of unused exports from static CommonJS modules. Defaults to false. /// Enable tree shaking of unused exports from static CommonJS modules. Defaults to false.
turbopack_cjs_tree_shaking: Option<bool>, turbopack_cjs_tree_shaking: Option<bool>,
/// Shorten ("mangle") the export names modules expose to each other. Defaults to false. /// Shorten ("mangle") the export names modules expose to each other. Defaults to false in
/// development mode, true in production mode.
turbopack_mangle_export_names: Option<bool>, turbopack_mangle_export_names: Option<bool>,
/// Enable scope hoisting of static CommonJS modules. Defaults to false. /// Enable scope hoisting of static CommonJS modules. Defaults to false.
turbopack_cjs_scope_hoisting: Option<bool>, turbopack_cjs_scope_hoisting: Option<bool>,
......
...@@ -463,7 +463,7 @@ Additionally, the following experimental options are available under `experiment ...@@ -463,7 +463,7 @@ Additionally, the following experimental options are available under `experiment
| `turbopackModuleFragments` | Currently in active development. This splits modules into fragments and chunks only import the used fragments of the modules. | `false` | `false` | | `turbopackModuleFragments` | Currently in active development. This splits modules into fragments and chunks only import the used fragments of the modules. | `false` | `false` |
| `turbopackRemoveUnusedImports` | Enable removing unused imports. Requires `turbopackRemoveUnusedExports`. | `false` | `true` | | `turbopackRemoveUnusedImports` | Enable removing unused imports. Requires `turbopackRemoveUnusedExports`. | `false` | `true` |
| `turbopackRemoveUnusedExports` | Enable removing unused exports. | `false` | `true` | | `turbopackRemoveUnusedExports` | Enable removing unused exports. | `false` | `true` |
| `turbopackMangleExportNames` | Shorten the export names modules expose to each other, to reduce bundle size. A module whose export names can be observed (an escaping namespace object, a dynamic `import()`, a CommonJS `require()`) keeps its original names. | `false` | `false` | | `turbopackMangleExportNames` | Shorten the export names modules expose to each other, to reduce bundle size. A module whose export names can be observed (an escaping namespace object, a dynamic `import()`, a CommonJS `require()`) keeps its original names. | `false` | `true` |
| `turbopackInferModuleSideEffects` | Enable local analysis to infer side-effect-free modules for better tree shaking. | `true` | `true` | | `turbopackInferModuleSideEffects` | Enable local analysis to infer side-effect-free modules for better tree shaking. | `true` | `true` |
| `turbopackScopeHoisting` | Enable scope hoisting. Always disabled in dev mode. | `false` | `true` | | `turbopackScopeHoisting` | Enable scope hoisting. Always disabled in dev mode. | `false` | `true` |
| `turbopackSharedRuntime` | Share the browser runtime across routes in a single `runtime.js` asset. Only applies to production builds. | N/A | `true` | | `turbopackSharedRuntime` | Share the browser runtime across routes in a single `runtime.js` asset. Only applies to production builds. | N/A | `true` |
......
...@@ -12,7 +12,6 @@ import type { NextParsedUrlQuery } from './request-meta' ...@@ -12,7 +12,6 @@ import type { NextParsedUrlQuery } from './request-meta'
import type { SizeLimit } from '../types' import type { SizeLimit } from '../types'
import type { SupportedTestRunners } from '../cli/next-test' import type { SupportedTestRunners } from '../cli/next-test'
import { INFINITE_CACHE } from '../lib/constants' import { INFINITE_CACHE } from '../lib/constants'
import { isStableBuild } from '../shared/lib/errors/canary-only-config-error'
import type { FallbackRouteParam } from '../build/static-paths/types' import type { FallbackRouteParam } from '../build/static-paths/types'
import type { MemoryEvictionMode, TurbopackGcOptions } from '../build/swc/types' import type { MemoryEvictionMode, TurbopackGcOptions } from '../build/swc/types'
import type { CacheLife } from './use-cache/cache-life' import type { CacheLife } from './use-cache/cache-life'
...@@ -1090,7 +1089,7 @@ export interface ExperimentalConfig { ...@@ -1090,7 +1089,7 @@ export interface ExperimentalConfig {
* can be observed by user code (a namespace object that escapes, a dynamic `import()`, a * can be observed by user code (a namespace object that escapes, a dynamic `import()`, a
* CommonJS `require()`) keeps its original names. * CommonJS `require()`) keeps its original names.
* *
* Defaults to `false` * Defaults to `true` for production builds and `false` in development.
*/ */
turbopackMangleExportNames?: boolean turbopackMangleExportNames?: boolean
...@@ -2471,10 +2470,10 @@ export const defaultConfig = Object.freeze({ ...@@ -2471,10 +2470,10 @@ export const defaultConfig = Object.freeze({
turbopackInferModuleSideEffects: true, turbopackInferModuleSideEffects: true,
turbopackPluginRuntimeStrategy: 'childProcesses', turbopackPluginRuntimeStrategy: 'childProcesses',
turbopackSharedRuntime: true, turbopackSharedRuntime: true,
// Pinned off for stable releases. Left unset on canary so the Turbopack side picks the // Left unset so the Turbopack side picks the default from the build mode (on for production
// default from the build mode (on for production builds, off in development) — see // builds, off in development) — see `NextConfig::turbopack_mangle_export_names`. An explicit
// `NextConfig::turbopack_mangle_export_names`. An explicit value always wins either way. // value always wins either way.
turbopackMangleExportNames: isStableBuild() ? false : undefined, turbopackMangleExportNames: undefined,
}, },
htmlLimitedBots: undefined, htmlLimitedBots: undefined,
bundlePagesRouterDependencies: false, bundlePagesRouterDependencies: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment