Skip to content

feat(vite): respect vite mode for env loading#4082

Merged
pi0 merged 1 commit intonitrojs:mainfrom
kricsleo:feat/respect-vite-mode
Mar 10, 2026
Merged

feat(vite): respect vite mode for env loading#4082
pi0 merged 1 commit intonitrojs:mainfrom
kricsleo:feat/respect-vite-mode

Conversation

@kricsleo
Copy link
Member

@kricsleo kricsleo commented Mar 8, 2026

🔗 Linked issue

resolves #4028

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Load .env.[mode] and .env.[mode].local files when using Nitro as a Vite plugin, matching Vite's env loading spec.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@kricsleo kricsleo requested a review from pi0 as a code owner March 8, 2026 13:38
@vercel
Copy link

vercel bot commented Mar 8, 2026

@kricsleo is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Mar 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: caa37c2c-2283-4c22-bc13-93510292528b

📥 Commits

Reviewing files that changed from the base of the PR and between bfbb207 and 423c6ba.

📒 Files selected for processing (1)
  • src/build/vite/plugin.ts

📝 Walkthrough

Walkthrough

Adds Vite mode-aware environment file resolution to Nitro initialization in the Vite plugin. The createNitro call is updated to pass a dotenv configuration that includes mode-specific .env files (.env.<mode> and .env.<mode>.local) alongside the default .env and .env.local files.

Changes

Cohort / File(s) Summary
Vite Plugin Nitro Integration
src/build/vite/plugin.ts
Added computation of dotenv file list with mode-specific files and updated createNitro() call to pass { dotenv: { fileName: dotenvFileNames } } configuration, enabling Nitro to respect Vite's --mode flag when loading environment variables.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows conventional commits format with type 'feat', scope 'vite', and clearly describes the main change of respecting Vite's mode for env loading.
Description check ✅ Passed The description is related to the changeset, explaining the purpose of loading mode-specific env files and linking to the relevant issue #4028.
Linked Issues check ✅ Passed The code changes fully address issue #4028 by computing mode-specific dotenv file names and passing them to Nitro's dotenv configuration via createNitro options.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing mode-specific env file loading for Nitro as a Vite plugin, with no out-of-scope modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kricsleo kricsleo changed the title feat(vite): respect vite mode for env loading feat(vite): respect vite mode for env loading Mar 8, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 8, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4082

commit: 002b81c

@pi0 pi0 merged commit e937ffb into nitrojs:main Mar 10, 2026
9 of 10 checks passed
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.

Nitro doesn't respect Vite's mode for env variables

2 participants