如何为React Native项目构建Hermes JS发布包?
生成Hermes专属JS包的命令
React Native CLI的bundle命令本身就能生成Hermes兼容的包,只需添加指定参数即可,不需要单独的新命令:
针对Android平台:
npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/ --hermes true针对iOS平台:
npx react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ios/main.jsbundle --assets-dest ios --hermes true
补充说明
- 核心参数是
--hermes true,它会触发CLI用Hermes编译器生成适配的字节码文件(.hbc),同时也会生成对应的JS bundle,满足Hermes运行的需求。 - 如果你的项目已经在
metro.config.js里默认启用了Hermes,直接执行常规的bundle命令也能生成Hermes兼容包,无需额外加参数。 - 要是你需要单独生成Hermes字节码文件(.hbc),可以直接调用Hermes编译器:
不过一般情况下,hermesc -O -output index.android.bundle.hbc index.android.bundlebundle命令会自动完成这一步,没必要手动操作。
内容的提问来源于stack exchange,提问作者Kirill Novikov
相关产品推荐
相关产品推荐

