在react-native.config.js中检测开发环境

时间:2020-11-07 22:34:23

标签: react-native

我想访问__DEV__中的react-native.config.js,所以我可以管理一些在开发和生产环境中链接的本机库,例如下面的示例:

const VECTOR_ICONS_FONTS_PATH =
  './node_modules/react-native-vector-icons/Fonts';
const VECTOR_FONTS = ['MaterialCommunityIcons.ttf'];

module.exports = {
  assets: ['./src/assets/fonts/nop/nop.ttf'],
  dependencies: {
    'react-native-vector-icons': {
      platforms: {
        ios: null,
        android: null,
      },
      assets: VECTOR_FONTS.map((font) => VECTOR_ICONS_FONTS_PATH + '/' + font),
    },
    'react-native-flipper': {
      platforms: {
        ios: null,
        android: __DEV__ ? undefined : null,
      },
    },
  },
};

但是,如果执行此操作,则会出现以下错误:

$ react-native run-android
error Unrecognized command "run-android".
info Run "react-native --help" to see a list of all available commands.
error Command failed with exit code 1.

1 个答案:

答案 0 :(得分:-1)

您使用的是哪个版本的Nodejs和NPM?

当项目未正确初始化时,有时可能会发生这种情况。 也许尝试以下方法:

  1. 如果不是LTS,请更新NodeJ / NPM
  2. 删除node_modules目录
  3. 运行npm install or yarn install
  4. 运行react-native init
  5. 运行react-native run-android

react-native run-android is unrecognized的重复项)