我是Bazel的新手。
我以为id是从尝试构建一个简单的nodejs项目开始的,它在构建过程中使用babel进行了一些转换,但问题是我似乎找不到找到将这些转换后的文件放入文件组的方法。
这是我的BUILD文件。
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
# Group all our initial code.
filegroup(
name = "src",
srcs = [
".babelrc",
"package.json",
"//config:src",
"//handlers:src",
"//migrations:src",
"//models:src",
"//services:src",
"//tasks:src",
"@dependencies//:node_modules",
],
)
# Group all our generated code.
filegroup(
name = "out",
srcs = [
"//:babel:runfiles" ### ???
],
)
nodejs_binary(
name = "babel",
entry_point = "babel-cli/bin/babel.js",
templated_args = [
".",
"--ignore node_modules,test/,migrations/,babel_bin_loader.js",
"-d out",
"--source-maps=both",
"--copy-files",
],
node_modules = "@nodejs_build_tools//:node_modules",
data = [
"//:src",
]
)
pkg_tar(
name = "build",
strip_prefix = "/",
package_dir = "/usr/src/app",
srcs = ["//:out"],
mode = "0755",
)
我的问题是我不确定如何从我的nodejs_binary规则引用运行文件。
https://github.com/bazelbuild/rules_nodejs/blob/master/internal/node/node.bzl#L130
似乎表明应该有:runfiles属性或类似属性?
谢谢! :)
答案 0 :(得分:0)
因此,事实证明,执行此操作的正确方法似乎是使用genrule实际调用已配置的nodejs二进制文件。例如
## Artifact Construction ##
genrule(
name = "construct_artifact",
outs = ["artifact.tar"],
cmd = """./$(location babel) . --ignore bazel-
out,node_modules,text/,migrations/ -d out/ --source-maps=both --copy-files && tar cvf $@ out/ """,
srcs = [
"//:src",
],
tools = [
"//:babel",
]
)