-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
70 additions
and
89 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,13 @@ | ||
import global from "./global"; | ||
import { maybe } from "./maybe"; | ||
|
||
// To keep string-based find/replace minifiers from messing with __DEV__ inside | ||
// string literals or properties like global.__DEV__, we construct the "__DEV__" | ||
// string in a roundabout way that won't be altered by find/replace strategies. | ||
const __ = "__"; | ||
const GLOBAL_KEY = [__, __].join("DEV"); | ||
|
||
function getDEV() { | ||
try { | ||
return Boolean(__DEV__); | ||
} catch { | ||
Object.defineProperty(global, GLOBAL_KEY, { | ||
// In a buildless browser environment, maybe(() => process.env.NODE_ENV) | ||
// evaluates as undefined, so __DEV__ becomes true by default, but can be | ||
// initialized to false instead by a script/module that runs earlier. | ||
value: maybe(() => process.env.NODE_ENV) !== "production", | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
}); | ||
// Using computed property access rather than global.__DEV__ here prevents | ||
// string-based find/replace strategies from munging this to global.false: | ||
return (global as any)[GLOBAL_KEY]; | ||
} | ||
return "__DEV__" in global | ||
? Boolean(global.__DEV__) | ||
// In a buildless browser environment, maybe(() => process.env.NODE_ENV) | ||
// evaluates as undefined, so __DEV__ becomes true by default, but can be | ||
// initialized to false instead by a script/module that runs earlier. | ||
: maybe(() => process.env.NODE_ENV) !== "production"; | ||
} | ||
|
||
export default getDEV(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters