以编程方式编译/构建项目引用,我使用ts.createSolutionBuilder
API。
问题是,在我的用例中,我没有tsconfig。在每个包的文件系统中写入的Json文件。相反,tsconfig。Json是根据其他标准计算的。
可以将编译器选项传递给这个方法,但它只是tsconfig。包含所有项目引用数据的根目录的Json。我如何传递每个项目/包的编译器选项?
我有点惊讶,在typescript中缺乏关于这方面的文档(好吧,4.3)。X),但看起来很简单——提供路径的参数可以接受配置链接。
下面是我的代码:
// this selects directories to use
const packages = getTSDirectoriesFromGlobs(process.cwd(), opts._, configName);
// so I basically add the tsconfig names to my paths
const rootnames = packages.map(x => join(x, configName || "tsconfig.json"));
// and then pass that as the second argument
const solution = createSolutionBuilder(nodeSystem, rootnames, {});
// and then...
const exitCode = solution.build();
很有魅力。:)
实际上,我会在我的PR to transform Hub中添加几个链接到上面的代码,我在这里介绍了链接:
- 这是PR本身 这是构建文件
- 这是实际的行
我真的很惊讶地看到它确实改善了构建时间这么多——仓库有一个很大的单仓库,所以看到它是如何工作的非常有趣。
无论如何,我希望这有助于。:)