Skip to content

feat: add import.meta.DEBUG - #18417

Closed
hybrist wants to merge 1 commit into
vitejs:mainfrom
hybrist:jk-import-meta-debug
Closed

hybrist wants to merge 1 commit into
vitejs:mainfrom
hybrist:jk-import-meta-debug

Conversation

@hybrist

@hybrist hybrist commented Oct 21, 2024 •

Copy link
Copy Markdown
Contributor

Description

Adds an alternative to process.env.NODE_ENV-based guards. It's a simple boolean and doesn't require the use of node-specific APIs in non-node code.

See: https://github.com/jkrems/md/blob/main/import-meta-debug.md
Or just skip ahead to the section that defines this new property: https://github.com/jkrems/md/blob/main/import-meta-debug.md#importmetaDEBUG.

The goal is to have this property reliably available across tools. PRs across bundlers:

I wouldn't be surprised if there's some bikeshedding on the name (.DEBUG vs .DEV vs .development vs ..?). So it's likely a good idea to hold off on landing it in any of the tools before there's a broader consensus on the name. The API itself seems simple enough that I'm not expecting a lot of churn.

@hybrist
hybrist force-pushed the jk-import-meta-debug branch 2 times, most recently from ca2800c to 8232f70 Compare October 21, 2024 18:21
Adds an alternative to `process.env.NODE_ENV`-based guards. It's a simple
boolean and doesn't require the use of node-specific APIs in non-node code.
@hybrist
hybrist force-pushed the jk-import-meta-debug branch from 8232f70 to 4148214 Compare October 21, 2024 19:06
@sapphi-red sapphi-red added the p2-to-be-discussed Enhancement under consideration (priority) label Oct 23, 2024
@sapphi-red

Copy link
Copy Markdown
Member

https://github.com/jkrems/md/blob/main/import-meta-debug.md#package-exports-development
How about using something like esm-env?

The downside of using import.meta is that the source code needs to be in ESM. I don't think it's that bad, but just to point it out.

I think this needs some kind of standard otherwise the whole benefit will disappear, but the discussion about that seems to be happening on the webpack PR.

(This is just my take. I'll try to talk about this in the next team meeting.)

@sapphi-red

Copy link
Copy Markdown
Member

Closing this PR as it seems Webpack isn't interested in this.

@sapphi-red sapphi-red closed this May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2-to-be-discussed Enhancement under consideration (priority)

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants