我正在为 React-Native Android 项目设置 Bazel 构建。由于我不会使用 Android Studio 和 Gradle,我需要调用 react-native cli 来创建 RN 包。我尝试了几种genrule
和规则的组合以及对、和.nodejs_binary
的调用。这些尝试以两个错误之一结束:react-native
npx react-native
react-native\cli.js
1)
error Unrecognized command "bundle".
debug We couldn't find a package.json in your project. Are you sure you are running it inside a React Native project?
2)
Error: EPERM: operation not permitted, chmod '/private/var/tmp/_bazel_joshnunez/bfd4b860cd0c2d2f0e40baa90bf393fd/sandbox/darwin-sandbox/471/execroot/native_modules/bazel-out/host/bin/external/androi
d_sample/src/rncli.sh.runfiles/npm/node_modules/@react-native-community/cli/build/commands/server/external/xsel'
这是我正在使用的 bazel 规则(许多排列用 # 注释掉):
nodejs_binary(
name = "rncli",
entry_point = "@npm//:node_modules/react-native/local-cli/cli.js",
node_modules = "@npm//:node_modules"
)
genrule (
name = "rnAndroidBundle",
outs = [ "main/assets/index.android.bundle" ],
cmd = "$(location :rncli) bundle --verbose --entry-file $(location :appEntry) --platform android --bundle-output $@",
#cmd = "npm run react-native bundle --verbose --entry-file $(location :appEntry) --platform android --bundle-output $@",
#cmd = "npx react-native bundle --verbose --entry-file $(location :appEntry) --platform android --bundle-output $@",
#cmd = "$(location @npm//:node_modules/react-native/cli.js) bundle --verbose --entry-file $(location :appEntry) --platform android --bundle-output $@",
#cmd = "node node_modules/react-native/local-cli/cli.js bundle --verbose --entry-file $(location :appEntry) --platform android --bundle-output $@",
#cmd = "node $(location @npm//react-native:node_modules/react-native/cli.js) bundle --verbose --entry-file external/android_sample/src/app.tsx --platform android --bundle-output $@",
#srcs = [ "@npm//react-native" ],
srcs = [ "appEntry" ],
#tools = [ "@npm//:node_modules/react-native/cli.js" ]
tools = [ ":rncli" ]
)
filegroup (
name = "appEntry",
srcs = [ "app.tsx" ]
)