1

我正在尝试将 Angular 项目集成到现有的 Bazel 构建系统中。当我尝试运行 angular build 时,出现以下错误。

Workspace configuration file (angular.json, .angular.json, workspace.json, .workspace.json) cannot be found in '/home/build/.cache/bazel/_bazel_build/46b74a3c1f9a666f55591a5719d9f2ba/sandbox/linux-sandbox/1/execroot/root' or in parent directories.

现在我的角度项目位于根工作区的子文件夹中,因此角度无法找到角度 json 文件。当我使用 angular devkit 的架构师包运行 angular build 时,也没有选项可以使用 args 指定 angular json 的确切位置,这可能会解决问题。

一种方法,我能想到的解决方法是在运行构建命令之前将 angular json 文件复制到工作区的根目录。我还有其他选择吗?

4

3 回答 3

1

您可以使用chdir

您基本上会将路径传递给该子文件夹,并且该工具将在运行 ng build 之前更改为该目录。我还必须通过将级别上移到根目录来更改 outDir 以使构建成功。

例如,如果chdir是 lib/sub/angular,那么outDir将是 ../../../$(@D)

于 2021-06-07T06:22:22.923 回答
1

Birju 的回答是肯定的。但我觉得它应该得到一些代码。

我还要补充一点,使用后设置输出目录chdir非常重要,否则你会因为构建声称成功而摸不着头脑,但是当你检查你的 bazel 输出时,什么都不会出现(一种无声的失败)请注意,在我的示例中,outputPath这个变量实际上取决于您使用的工具,而不是 Bazel 本身。

foo/BUILD.bazel

load("@npm//@angular-devkit/architect-cli:index.bzl", "architect") # architect ruleset being generated by bazel itself. (I.e. `foo/`)

architect(
    name = "build",
    args = [
        "frontend:build",
        "--outputPath=../$(@D)", # This output argument needs to point to the wherever the workspace directory is. Otherwise, your bazel build will succeed but nothing will appear.
                               
    ],
    chdir = package_name(),      # package_name() gets the path of wherever the current build file is

    # any other arguments...
)
于 2021-09-29T04:58:21.550 回答
0

万一有人试图通过使用架构师来构建 Angular 库,这不允许outputPath. 我按照这个例子

其中,chdir = package_name(),正如@Cameron @Birju 所说,肯定需要这条线。代码中的 args$(@D)需要更改到正确的位置。否则,它位于沙箱中,将被删除。

在示例中,一切运行良好。但就我而言,我的 GUI 项目位于subdir1/subdir2dir中WORKSPACE,而我的 lib 位于subdir1/subdir2/projects/mylib. 我没有.bazelrc示例中的文件。所以我最终不得不更改${@D}添加很多内容../以退出沙箱目录,例如“../../../../../../../../. ./execroot/bla/$(@D)"

于 2022-01-17T20:31:32.107 回答