-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add import.meta.DEBUG #18876
base: main
Are you sure you want to change the base?
feat: add import.meta.DEBUG #18876
Conversation
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
The committers listed above are authorized under a signed CLA. |
For maintainers only:
|
IMO this is not necessary to add into the core, user can add |
The target audience for this feature is library authors. Which means that adding a DefinePlugin to the users config isn't something they can do. I'd be surprised if a library author wouldn't just use (or keep using) process.env.NODE_ENV if the alternative requires each user of the library to set custom bundler configs. |
@ahabhgk I agree, library developers should be able to define the mode without additional guides on how to configure the bundle |
I agree with this point. But libraries already has various similar variables, such as |
@ahabhgk Does |
No, rspack keep the same with webpack (supports |
This comment was marked as outdated.
This comment was marked as outdated.
On topic: I agree that universal support for To recap from the explainer, the two big issues with
Neither of those are necessarily "fatal flaws" but it's a bit sad if the recommended replacement for |
@jkrems I'm afraid that for this to be standard we need to mention here all the developers of bundlers and maybe even TC39, I would not like to create problems for future library developers by adopting some rules that will be revised. |
Definitely! This isn't worth landing unless all bundlers agree to support it. Since it's based on the "development" condition and that condition is only a cross-bundler convention, I'm not sure if there's a better "standards venue" than cross-bundler agreement to do it. P.S.: FWIW, I'd love it if there was a central place where cross-bundler APIs were documented/specified - or even a "test262 but for bundlers" at some point. |
@jkrems maybe we can start it here - https://github.com/tc39/ecma262 or https://github.com/tc39/proposals and ask where we can start discussion |
(For context, I'm an - admittedly not very active - TC39 delegate.) I'll ask in the TC39 chat if there's appetite to pursue this at that level but in the past my feeling was that |
@jkrems I understand that on the other hand it could allow standardizing the behavior of libraries in different environments, not just for bundles, which could have its advantages. |
FYI, there's now a dedicated channel for JS tool maintainers/contributors: https://matrix.to/#/#tc39-tools-:matrix.org P.S.: Matrix because that's where other TC39 chats are happening. If you think another place would be more appropriate, happy to move discussions there as well. :) |
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.What kind of change does this PR introduce?
Feature: It's a new
import.meta
property.Did you add tests for your changes?
Tests are included.
Does this PR introduce a breaking change?
This shouldn't break any code unless somebody currently depends on
import.meta.DEBUG
being false in development. I'm not aware of any use of this property though.What needs to be documented once your changes are merged?
This should be added to the properties on https://webpack.js.org/api/module-variables/.