我有以下文件夹结构
proj-folder
|-app1
|-app2
|-core
使用ng new app1
命令创建的app1和app2文件夹。
我只想放上corelib文件夹模块,服务和组件来分享app1和app2。我不想为我的核心库创建一个npm包。
我已经尝试了很多东西。几乎工作的是:
在corelib文件夹上,我复制了package.json表单app1,然后是npm install
,然后在文件tsconfig.json上的app1上更改路径,如下所示:
"baseUrl": "src",
"paths": {
"@core/*": ["../../core/src/*"],
}
如果我在app1上ng build
完美无缺。但是当我ng build --prod
时,我收到以下错误:
ERROR in ../../core/core.module.ts(5,2): Error during template compile of 'CoreModule'
Function calls are not supported in decorators but 'ɵmakeDecorator' was called in 'NgModule'
'NgModule' calls 'ɵmakeDecorator'.
如何共享lib可以如此复杂?我读了很多地方,但没有一个简单的方法。我错过了什么?
答案 0 :(得分:2)
问题是package.json
上@angular上的不同版本以及tsconfig.json上的以下行:
"@angular/*": ["../node_modules/@angular/*"]
<强>更新强>
在主应用程序上添加导入共享库的每个库tsconfig.json
非常重要。
示例:
"@angular/*": ["../node_modules/@angular/*"],
"rxjs/*" : ["../node_modules/rxjs/*"],
"firebase/*": ["../node_modules/firebase/*"],
"angularfire2/*": ["../node_modules/angularfire2/*"]
完整代码:link