Skip to content

fix(rolldown): run the devtools build with a production NODE_ENV - #587

Open
zahidzorbaz wants to merge 1 commit into
vitejs:mainfrom
zahidzorbaz:fix/rolldown-build-production-node-env
Open

zahidzorbaz wants to merge 1 commit into
vitejs:mainfrom
zahidzorbaz:fix/rolldown-build-production-node-env

Conversation

@zahidzorbaz

Copy link
Copy Markdown
Contributor

Description

The Rolldown panel's Run build with devtools produced a development bundle. The button spawns vite build from the running dev server, and the hub's startChildProcess() passes the parent env through, so the child inherits the NODE_ENV=development that Vite sets for the dev server. vite build keeps an already-set NODE_ENV and replaces process.env.NODE_ENV with process.env.NODE_ENV || mode, so every library's dev-only branches stayed in the bundle the panel then analysed.

getBuildCommand() now sets NODE_ENV: 'production', which is what a plain vite build resolves to. The confirmation dialog shows it too: NODE_ENV=production VITE_DEVTOOLS_ROLLDOWN=true vite build.

The hub keeps passing the env through, since terminal sessions generally need the parent env (PATH, proxies, user variables). The build runner is the caller that knows the build must not inherit the dev server's NODE_ENV.

Linked Issues

Fixes #586

Additional context

  • Tests: packages/rolldown/src/node/rolldown/__tests__/build-runner.test.ts checks getBuildCommand() and the options startBuild() passes to startChildProcess(). Both fail on main.
  • Vite 8.3.0 behaviour checked with a two-line app: vite build drops an if (process.env.NODE_ENV !== 'production') branch, while NODE_ENV=development vite build keeps it.
  • Impact seen in a real Vue app: first-load JS 259.2 KB gz via the button vs 200.9 KB gz for a plain vite build of the same commit (@vue/devtools-kit only in the former).
  • Gates on Windows 11 / Node 24.21: pnpm lint, pnpm typecheck and pnpm build pass. pnpm test passes except the two locale-dependent packages/ui bytesToHumanSize cases, which fail the same way on a clean main here (tr-TR locale).

🤖 Generated with Claude Code

"Run build with devtools" spawns `vite build` from the dev server, so the
child inherits `NODE_ENV=development` that Vite set for the dev server.
`vite build` keeps an already-set `NODE_ENV`, so the build kept every
library's dev-only branches and the Rolldown panel analysed a development
bundle. Pin `NODE_ENV=production`, which is what a plain `vite build`
resolves to.

Fixes vitejs#586

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rolldown "Run build with devtools" produces a development build (inherits the dev server's NODE_ENV)

1 participant