我在很多开源项目中看到用 __DEV__ 变量来判断是否是开发环境,但是全局搜索也没找到该变量是在哪里定义的。
__DEV__
react-router项目:https://github.com/ReactTraining/react-router/blob/v6.0.0-beta.0/packages/react-router/index.tsx history项目:https://github.com/ReactTraining/history/blob/master/packages/history/index.ts
React 项目?
别的项目这个就很罕见了。
说白了就是通过 metro 打包时注入到环境变量里的一个字符串,到时候解析 JS 语法树的时候会批量替换掉它。
现在往往都用 process.env.NODE_ENV 来代替了。
process.env.NODE_ENV
P.S. 相关源码:
声明: https://github.com/facebook/m...设置:https://github.com/facebook/r...
设置:https://github.com/facebook/r...
2.1m questions
2.1m answers
60 comments
56.8k users