【问题标题】:Best Practice for forking jsCodeLocation based on environment基于环境分叉jsCodeLocation的最佳实践
【发布时间】:2017-07-31 15:36:30
【问题描述】:

我希望能够在本地或应用商店上运行我的 React-Native 应用。

目前我有两行:

//  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
  jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

我酌情评论或取消评论。是否有可能做类似if process.end.NODE_ENV === production(除了适用于Objective C/iOS)这样的事情来真正分叉这个?

【问题讨论】:

    标签: ios objective-c react-native xcodebuild


    【解决方案1】:

    选择项目->选择“构建设置”->搜索“预处理器宏”->定义宏,如STATE_DEVELOPMENT = 0或1。

    在 Release 部分定义 STATE_DEVELOPMENT = 0,在 Debug 部分定义 STATE_DEVELOPMENT = 1。

    #if STATE_DEVELOPMENT
            jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
    #else
            jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
    #endif
    

    【讨论】:

    • 这不能实现到 react-native 中吗?你在这里有很好的公关机会。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-27
    • 1970-01-01
    • 2019-10-19
    • 2016-10-26
    • 2015-06-09
    • 1970-01-01
    相关资源
    最近更新 更多