gpt4 book ai didi

angular - 我可以使用 @ngtools/webpack 发出类型/声明 (.d.ts) 和装饰器元数据 (.metadata.json) 文件吗?

转载 作者:太空狗 更新时间:2023-10-29 17:21:16 24 4
gpt4 key购买 nike

我正在开发一个与 AOT 编译兼容的 Angular 库。我已经使用 ngc 周围的一些 gulp 任务启动并运行它,但我更喜欢使用 @ngtools/webpack,因为它允许我使用更直接的方法SASS 和 PUG 用于我的样式和模板。但是,我找不到从其虚拟文件系统中获取声明或元数据文件的方法。有没有办法发出这些文件?

最佳答案

对于声明,您必须更改const lambda => export function。

也就是

const declarations = () => [
Component
];

export function declarations() {
return [
Components
];
}

然后将 package.json 中 scripts 部分中的 tsc 替换为 ngc

现在从 ( this comment on github )

All referenced libraries must include the .metadata.json file along side any .d.ts files they produce otherwise they will not work correctly with ngc. The .metadata.json file contains the information we need that was in the original .ts file but was not included in the .d.ts file. If we don't have that information we cannot generate the factories for the library.

  • 因此,请确保 _.metadata.json 文件位于其关联的 *.d.ts 文件旁边。

    <
  • 由于您使用的是 webpack,因此您必须先使用 ngc,然后再对编译后的代码使用 webpack。


来源
1. Making your Angular 2 library statically analyzable for AoT
2. Getting your Angular 2 library ready for AoT

关于angular - 我可以使用 @ngtools/webpack 发出类型/声明 (.d.ts) 和装饰器元数据 (.metadata.json) 文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46329836/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com