Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

请问Node项目__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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

React 项目?

别的项目这个就很罕见了。

说白了就是通过 metro 打包时注入到环境变量里的一个字符串,到时候解析 JS 语法树的时候会批量替换掉它。

现在往往都用 process.env.NODE_ENV 来代替了。


P.S. 相关源码:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...