-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
Hi, new contributor here, trying to be help.
As of now, some tools/libs do production<->dev detection for various reasons:
- example: bundlers removing dead code in prod by evaluating
process.env.NODE_ENV
- example: an assertion lib dropping the assertion error message in production: https://github.com/alexreardon/tiny-invariant?tab=readme-ov-file#dropping-your-message-for-kb-savings by putting an optimized branch behind
process.env.NODE_ENV
- example: automatically enabling/disabling a "strict mode" in dev, such as React "StrictMode"
However this process.env.NODE_ENV
expression is not available by default in all runtimes, for ex. Cloudflare Workers: alexreardon/tiny-invariant#205 (without node compat)
There are already existing ideas to standardize this feature, for ex into a boolean __DEV__
: https://github.com/jaredpalmer/tsdx?tab=readme-ov-file#__dev__
I suggest this feature to be considered in minimum common API. This expression should be easily detected by bundlers but also be working in production, being immutable and set from the outside.
Thanks!
edit: added an example
sgammon and thescientist13
Metadata
Metadata
Assignees
Labels
No labels