跳到主要内容

client

根据当前的环境调用不同的逻辑文件,并在生产环境检验死代码是否移除干净。

'use strict';

// 校验是否是开发环境
function checkDCE() {
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined' ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE !== 'function'
) {
return;
}
if (process.env.NODE_ENV !== 'production') {
// This branch is unreachable because this function is only called
// in production, but the condition is true only in development.
// Therefore if the branch is still here, dead code elimination wasn't
// properly applied.
// Don't change the message. React DevTools relies on it. Also make sure
// this message doesn't occur elsewhere in this function, or it will cause
// a false positive.
// 这个分支是不可达的,因为这个函数只在生产环境中被调用,但是条件只在开发环境中为真。因此,如果
// 分支仍然存在,说明死代码消除没有正确应用。不要更改这条信息。React DevTools 依赖它。还要确
// 保这个函数的其他地方没有出现这条信息,否则会导致误报。
throw new Error('^_^');
}
try {
// Verify that the code above has been dead code eliminated (DCE'd).
// 验证上面的代码是否已被消除死代码 (DCE)。
__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(checkDCE);
} catch (err) {
// DevTools shouldn't crash React, no matter what.
// We should still report in case we break this code.
// 不管怎样,开发者工具不应该让 React 崩溃。如果我们破坏了这段代码,仍然应该报告。
console.error(err);
}
}

if (process.env.NODE_ENV === 'production') {
// DCE check should happen before ReactDOM bundle executes so that
// DevTools can report bad minification during injection.
// DCE 检查应该在 ReactDOM 包执行之前进行,这样开发者工具可以在注入过程中报告错误的压缩。
checkDCE();
module.exports = require('./cjs/react-dom-client.production.js');
} else {
module.exports = require('./cjs/react-dom-client.development.js');
}