【问题标题】:`Bazel run` won't find static file dependency in bazel-bin when running nodejs_image运行nodejs_image时,`Bazel run`不会在bazel-bin中找到静态文件依赖项
【发布时间】:2021-12-19 21:19:00
【问题描述】:

我正在尝试让规则 docker nodejs_image 使用 bazel 运行。

我的命令是

bazel run :image.binary

这是我的规则:

load("@npm//@bazel/typescript:index.bzl", "ts_project")
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")

ts_project(
    name = "typescript_build",
    srcs = glob([
        "src/**/*",
    ]),
    allow_js = True,
    out_dir = "build",
    deps = ["@npm//:node_modules"],
)

nodejs_image(
    name = "image",
    data = [
        ":package.json",
        ":typescript_build",
        "@npm//:node_modules",
    ],
    entry_point = "build/app.js",
)

基本上,我需要package.json 文件,因为它包含Node 执行时的一些重要配置信息。如果我打电话给bazel build :image 然后抓取/运行该图像,一切正常。但是如果我打电话给bazel run :image,它基本上可以工作,只是它找不到package.json

当我检查 bazel-bin/ 文件夹时,我注意到 package.json 不包括在内,但内置的 typescript 和 node_modules 是。我猜是因为我没有在 package.json 上运行任何先前的规则,它没有被添加到 bin 中,但我真的不知道如何解决这个问题。

【问题讨论】:

    标签: bazel bazel-rules-nodejs


    【解决方案1】:

    所以,基本上,如果你只使用 copy_to_binjs_library 这样的规则,我认为它们的目的是帮助将静态文件放入你的 bazel-bin。

    https://bazelbuild.github.io/rules_nodejs/Built-ins.html#copy_to_bin

    ts_project(
        name = "typescript_build",
        srcs = glob([
            "src/**/*",
        ]),
        allow_js = True,
        out_dir = "build",
        deps = ["@npm//:node_modules"],
    )
    
    js_library(
        name = "library",
        srcs = ["package.json"],
        deps = [":typescript_build"],
    )
    
    nodejs_image(
        name = "image",
        data = [
            ":library",
            "@npm//:node_modules",
        ],
        entry_point = "build/app.js",
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-01
      • 1970-01-01
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      • 2021-10-16
      相关资源
      最近更新 更多