升级到使用Angular 5后,我遇到了使用Angular Module Package的问题。我已经确定问题出在Angular CLI Compiler(NGC)上。我期待编译的javascript中编译器的以下输出:
LibService.ctorParameters = () => [];
class LibModule {
}
LibModule.decorators = [
{ type: NgModule, args: [{
declarations: [LibComponent],
providers: [LibService],
exports: [LibComponent]
},] },
];
/**
* @nocollapse
*/
LibModule.ctorParameters = () => [];
相反,我得到的结果是:
class LibModule {
}
显然没有任何描述该模块的装饰器或注释。包含的服务和组件也是如此。
我的tsconfig.json如下所示:
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"inlineSources": true,
"declaration": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"skipLibCheck": true,
"stripInternal": true,
"lib": [
"es2015",
"dom"
]
}
}
我的tsconfig.lib.json是:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib-es2015/",
"target": "es2015",
"rootDir": "./",
"baseUrl": "",
"types": []
},
"files": [
"./index.ts",
"./typings.d.ts"
],
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"skipTemplateCodegen": true,
"flatModuleOutFile": "quickstart-lib.js",
"flatModuleId": "quickstart-lib",
"genDir": "../../out-tsc/lib-gen-dir/"
}
}
我在用于在4.0编译器下构建的javascript中使用的行是:
ngc({ project: `${tempLibFolder}/tsconfig.lib.json` })
,对于5.0编译器,它是:
ngc(['-p', `${tempLibFolder}/tsconfig.lib.json` ])
我无法找到有关angularCompilerOptions
提供任何指导的其他选项的任何良好文档。
当我编译时,我收到此警告,我无法找到有关解决此问题的有用信息:
'Component', 'Injectable' and 'NgModule' are imported from external module '@angular/core' but never used