Skip to content

feat(config): support multiple env files - #1110

Merged
sxzz merged 1 commit into
mainfrom
feat/multiple-env-files
Oct 28, 2026
Merged

sxzz merged 1 commit into
mainfrom
feat/multiple-env-files

Conversation

@sxzz

@sxzz sxzz commented Oct 28, 2026

Copy link
Copy Markdown
Member

AI usage

  • No AI was used in this PR.
  • AI was used: Claude Code + Claude Opus 5.5
    • I have carefully reviewed the AI-generated content myself.

Description

envFile (and --env-file) now accept multiple files, e.g. envFile: ['.env', '.env.local']. Files are loaded in order, so later files override earlier ones, and missing files are skipped (as in Vite). The precedence stays env files < process.env < env. Env files are still opt-in: no automatic loading, no envDir or mode.

Loaded env files are added to the config deps, so editing one restarts the build in watch mode. Per-config configDeps were never merged into the deps used by the watcher, so this also makes fromVite config deps trigger a restart.

Linked Issues

Closes #1056

Additional context

  • A missing file is now skipped instead of throwing, including with a single string.
  • An env file that doesn't exist when watch starts isn't watched, so creating it later needs a manual restart (r).

Copilot AI balanced review requested due to automatic review settings October 28, 2026 07:19
@netlify

netlify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for tsdown-main ready!

Name Link
🔨 Latest commit 4e612b5
🔍 Latest deploy log https://app.netlify.com/projects/tsdown-main/deploys/6ae1a212507923e384e57f11
😎 Deploy Preview https://deploy-preview-1110--tsdown-main.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Oct 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

tsdown

pnpm add https://pkg.pr.new/rolldown/tsdown@1110 -D
npm i https://pkg.pr.new/rolldown/tsdown@1110 -D
yarn add https://pkg.pr.new/rolldown/tsdown@1110.tgz -D

create-tsdown

pnpm add https://pkg.pr.new/rolldown/tsdown/create-tsdown@1110 -D
npm i https://pkg.pr.new/rolldown/tsdown/create-tsdown@1110 -D
yarn add https://pkg.pr.new/rolldown/tsdown/create-tsdown@1110.tgz -D

@tsdown/css

pnpm add https://pkg.pr.new/rolldown/tsdown/@tsdown/css@1110 -D
npm i https://pkg.pr.new/rolldown/tsdown/@tsdown/css@1110 -D
yarn add https://pkg.pr.new/rolldown/tsdown/@tsdown/css@1110.tgz -D

@tsdown/exe

pnpm add https://pkg.pr.new/rolldown/tsdown/@tsdown/exe@1110 -D
npm i https://pkg.pr.new/rolldown/tsdown/@tsdown/exe@1110 -D
yarn add https://pkg.pr.new/rolldown/tsdown/@tsdown/exe@1110.tgz -D

tsdown-migrate

pnpm add https://pkg.pr.new/rolldown/tsdown/tsdown-migrate@1110 -D
npm i https://pkg.pr.new/rolldown/tsdown/tsdown-migrate@1110 -D
yarn add https://pkg.pr.new/rolldown/tsdown/tsdown-migrate@1110.tgz -D

commit: 4e612b5

@sxzz
sxzz merged commit 5d55836 into main Oct 28, 2026
18 checks passed
@sxzz
sxzz deleted the feat/multiple-env-files branch October 28, 2026 07:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Automatic restarts leave the replacement watcher unmanaged, shared env-file registration creates quadratic watch setup work, and empty env-file paths can cause directory read errors.

3 open issues
What changed in this PR

Adds opt-in support for multiple environment files in tsdown, addressing #1056, and connects loaded files to watch-mode configuration reloads.

Changes:

  • Accept ordered env-file arrays and repeated --env-file flags, skipping missing files while preserving environment-variable precedence.
  • Merge per-config dependencies into restart tracking, including env files and fromVite dependencies.
  • Update documentation, schemas, API snapshots, and integration coverage.
File Description
tests/​e2e.test.ts Tests multiple files, override order, and missing-file handling.
tests/​__snapshots__/​multiple-env-files.snap.md Records bundled environment values.
src/​config/​types.ts Allows and documents env-file arrays.
src/​config/​options.ts Loads files in order and tracks loaded dependencies.
src/​config/​index.ts Merges per-config dependencies into global tracking.
src/​cli.ts Advertises repeatable env-file flags.
skills/​tsdown/​references/​reference-cli.md Documents multiple-file CLI usage.
schema.json Allows string or array env-file values.
docs/​zh-CN/​reference/​cli.md Updates Chinese CLI guidance and examples.
docs/​reference/​cli.md Updates English CLI guidance and examples.
snapshots/​tsnapi/​index.snapshot.d.ts Updates the main API type snapshot.
snapshots/​tsnapi/​config.snapshot.d.ts Updates the configuration API type snapshot.

Review effort: Balanced

Comment thread src/config/index.ts
Comment on lines +76 to +77
for (const config of configs) {
config.configDeps.forEach((dep) => globalDeps.add(dep))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 17bd0fc: config deps are no longer merged into the shared set. Each watcher now gets the shared deps plus its own config's configDeps.

Comment thread src/config/options.ts
if (envFile) {
const resolvedPath = path.resolve(cwd, envFile)
const envFromFiles: Record<string, string | undefined> = {}
for (const file of toArray(envFile)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 17bd0fc: empty env file paths are skipped again, with a test.

Comment thread src/config/options.ts
} else {
// precedence: process.env < tsdown option
env = { ...envFromProcess, ...env }
configDeps.add(resolvedPath)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. This predates this PR, since config file changes and the r shortcut restart the same way. Leaving it for a separate fix.

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.

Reading Environment Variables from multiple .env Files

3 participants