Skip to content

Add support for ignoring .env files with # WRANGLER_IGNORE comment#12724

Open
dario-piotrowicz wants to merge 3 commits intomainfrom
dario/ignore-env-file
Open

Add support for ignoring .env files with # WRANGLER_IGNORE comment#12724
dario-piotrowicz wants to merge 3 commits intomainfrom
dario/ignore-env-file

Conversation

@dario-piotrowicz
Copy link
Member

@dario-piotrowicz dario-piotrowicz commented Mar 1, 2026

This PR adds support for ignoring .env files with # WRANGLER_IGNORE comment


A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@changeset-bot
Copy link

changeset-bot bot commented Mar 1, 2026

🦋 Changeset detected

Latest commit: b5323bb

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Mar 1, 2026
@dario-piotrowicz dario-piotrowicz changed the title Dario/ignore env file Add support for ignoring .env files with # WRANGLER_IGNORE comment Mar 1, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2026

✅ All changesets look good

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 1, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12724

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12724

miniflare

npm i https://pkg.pr.new/miniflare@12724

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12724

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12724

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12724

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12724

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12724

wrangler

npm i https://pkg.pr.new/wrangler@12724

commit: b1b363d

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 4, 2026
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Will the Cloudflare vite-plugin generate a .env that contains this comment or is it up to the user to add it? Will then know when it is necessary? Is there an issue related to this?


// Check if file should be ignored
if (shouldIgnoreEnvFile(contents)) {
logger.info(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.info(
logger.debug(

Note that we have a silent parameter that suggests that we should not be outputting logs when true.

So if you do want to use logger.log here, you should wrap it in a if (!silent) block.

Copy link
Member Author

Choose a reason for hiding this comment

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

if (!silent) added 🫡

b5323bb

@github-project-automation github-project-automation bot moved this from Approved to In Review in workers-sdk Mar 4, 2026
@jamesopstad jamesopstad self-requested a review March 4, 2026 15:11
@jamesopstad
Copy link
Contributor

I removed my approval because I've thought about it a bit more and I'm less sure this is a good idea. For one, WRANGLER_IGNORE comment is confusing because the files will still be read by Wrangler in development. But also, I'm wondering why users can't just use different names for environment variables that they don't want to be read at deploy time?

@petebacondarwin
Copy link
Contributor

I removed my approval because I've thought about it a bit more and I'm less sure this is a good idea. For one, WRANGLER_IGNORE comment is confusing because the files will still be read by Wrangler in development. But also, I'm wondering why users can't just use different names for environment variables that they don't want to be read at deploy time?

I'm glad you are thinking about this more. I felt uncomfortable about it as a solution but couldn't put my finger on why so didn't want to block.

@dario-piotrowicz
Copy link
Member Author

I removed my approval because I've thought about it a bit more and I'm less sure this is a good idea. For one, WRANGLER_IGNORE comment is confusing because the files will still be read by Wrangler in development.

No it doesn't, this change applies across the board, so it applies to wrangler dev as well

But also, I'm wondering why users can't just use different names for environment variables that they don't want to be read at deploy time?

They sure can and that's a valid comment here, however I'd like to push back saying that asking users to work around these sort of thing is not a great DX. In my opinion it would be a much nicer DX for them if they could be allowed to tell wrangler not to use .env files when they don't want it to. Without this, the alternative for a user would be to make sure that they don't use any of the already-reserved variable names, which again is totally possible and not a huge deal, but also not an ideal DX in my opinion

@jamesopstad
Copy link
Contributor

I removed my approval because I've thought about it a bit more and I'm less sure this is a good idea. For one, WRANGLER_IGNORE comment is confusing because the files will still be read by Wrangler in development.

No it doesn't, this change applies across the board, so it applies to wrangler dev as well

Ah, I hadn't appreciated that it's the same loadDotEnv function that gets used in getVarsForDev. That's arguably more problematic though, because it means this WRANGLER_IGNORE comment also applies to reading secrets from .env files when using Vite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants