如何在bazel/webpack中设置绝对导入?

4
我想在我的代码库的另一个部分导入一个typescript模块,而不需要在我的导入中添加一堆“../..”以返回到我的bazel工作区的根目录。我该如何设置webpack的绝对导入(相对于我的工作区)? 我需要在webpack.config.js中设置一些内容吗?如果需要,是什么? 以下是说明问题的最简配置:
folder1/
    moduleA.ts
    BUILD
folder2/
    moduleB.ts
    BUILD
WORKSPACE

工作区

workspace(
    name = "myworkspace",
)

...

* **moduleA.ts ***

// TS COMPILER CAN FIND THIS BUT WEBPACK CAN'T FIND THIS
import { thing } from "myworkspace/folder2/moduleB";  

...

文件夹1/BUILD

load("@npm_bazel_typescript//:index.bzl", "ts_library")
load("@npm//webpack-cli:index.bzl", webpack = "webpack_cli")

ts_library(
    name = "moduleA",
    srcs = ["moduleA.ts"],
    deps = [
        "//folder2:moduleB",
    ],
)

filegroup(
    name = "moduleA.js",
    srcs = [
        "moduleA",
    ],
    output_group = "es6_sources",
    visibility = ["//visibility:public"],
)

webpack(
    name = "bundle",
    outs = ["app.bundle.js"],
    args = [
        "$(locations :moduleA.js)",
        "--config",
        "$(execpath //:webpack.config.js)",
        "-o",
        "$@",
    ],
    data = [
        ":moduleA.js",
        "//:webpack.config.js",
        "@npm//:node_modules",
    ],
    visibility = ["//visibility:public"],
)

你解决了吗?可以分享一下你是怎么做的吗? - Dzintars
是的 - 有点。请参见此处的线程:https://github.com/bazelbuild/rules_nodejs/issues/1952 - Wesley
1个回答

1

问题已经在这里得到解决。

事实证明,问题在于文件组没有从moduleA推断出需要包含//folder2:moduleB。将//folder2:moduleB添加到文件组的srcs中可以解决我的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接