代码之家  ›  专栏  ›  技术社区  ›  hamidfzm AlexLordThorsen

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

  •  0
  • hamidfzm AlexLordThorsen  · 技术社区  · 5 年前

    __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.
    
    0 回复  |  直到 5 年前
        1
  •  -1
  •   Sohail    5 年前

    当项目未正确初始化时,有时会发生这种情况。

    1. 如果不是LTS,更新NodeJs/NPM
    2. 删除node\u modules目录
    3. npm install or yarn install
    4. 跑 react-native init
    5. 跑 react-native run-android

    (副本) react-native run-android is unrecognized

    推荐文章