入口 | Sanitarium

入口

小于 1 分钟

入口

导出对象

入口将 Redux 提供的一些对象导出:

export {
  createStore,
  combineReducers,
  bindActionCreators,
  applyMiddleware,
  compose,
  __DO_NOT_USE__ActionTypes,
}

环境判断

/*
 * This is a dummy function to check if the function name has been altered by minification.
 * If the function has been minified and NODE_ENV !== 'production', warn the user.
 */
function isCrushed() {}

if (
  process.env.NODE_ENV !== 'production' &&
  typeof isCrushed.name === 'string' &&
  isCrushed.name !== 'isCrushed'
) {
  warning(
    'You are currently using minified code outside of NODE_ENV === "production". ' +
      'This means that you are running a slower development build of Redux. ' +
      'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' +
      'or setting mode to production in webpack (https://webpack.js.org/concepts/mode/) ' +
      'to ensure you have the correct code for your production build.'
  )
}

这里通过isCrushed这个空函数的函数名是否变化来判断当前是否是压缩后的代码,如果函数名不再是isCrushed,说明将 Redux 代码压缩了。由于 Redux 发布的是未压缩的版本,如果在开发环境下对 Redux 代码进行了压缩,打包构建会比较慢,这里会打出这个提示来提示开发者。

上次编辑于:
贡献者: mickmetalholic