组件中的角AOT相对路径 [英] Angular AOT Relative paths in components
问题描述
我在这里问是因为我无法在线找到完整的文档。
此处的示例太简单了。
我有一个包含多个组件和一些模块的应用程序。用ngc编译后,我遇到了很多错误。我发现修复它们的方法是使用相对路径。
因此,我在所有组件中都使用了 moduleId:module.id, 。
但是现在编译器告诉我:
' 找不到名称'模块' '
I'm asking here because I could't find complete documentation online. The example here is too simple. I've an app with several components and some modules. After compile with ngc, I had lot of errors. The way I found to fix them was use relative paths. So I use 'moduleId: module.id,' in all my components. But now the compiler tells me: ' Cannot find name 'module' '
据我了解,这是因为我声明了AoT的以下编译选项:
As I understand, that is becuase I'm declaring the following compile options for AoT:
{
"compilerOptions": {
"target": "es5",
---> "module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit" : true
}
}
而不是使用 module: commonjs, 。
如何解决此问题?
Instead of using "module": "commonjs",. How can I fix this?
如何在要生成AOT构建的同时使用相对路径?
How can I use relative paths at the same time I want to generate the AOT build?
谢谢!
推荐答案
一个快速(可能还很脏)的解决方法是直接写路径
A quick (and maybe dirty) fix is just to write the path directly as a string in the moduleId parameter.
So而不是:
moduleId: module.id
写:
moduleId: 'path/to/my/app/'
您可以在开发过程中将其与Component Relative Paths一起使用,并且在创建AoT捆绑包时,ngc不会抱怨找不到module.id。
This you can use with Component Relative Paths during development, and when creating the AoT bundle ngc won't complain about not finding module.id.
这篇关于组件中的角AOT相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!