Angular-带有预构建插件的Monorepo
以下是我正在使用的monorepository工作区的当前版本:Angular-带有预构建插件的Monorepo,angular,nrwl-nx,Angular,Nrwl Nx,以下是我正在使用的monorepository工作区的当前版本: > node --max_old_space_size=8000 ./node_modules/@nrwl/cli/bin/nx "version" _ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| /
> node --max_old_space_size=8000 ./node_modules/@nrwl/cli/bin/nx "version"
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 10.0.2
Node: 12.16.1
OS: win32 x64
Angular: 10.0.3
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.901.11
@angular-devkit/build-angular 0.1000.2
@angular-devkit/build-ng-packagr 0.1000.2
@angular-devkit/build-optimizer 0.901.11
@angular-devkit/build-webpack 0.901.11
@angular-devkit/core 9.1.11
@angular-devkit/schematics 10.0.2
@angular/cdk 10.0.2
@angular/cli 10.0.2
@angular/flex-layout 10.0.0-beta.32
@angular/material 10.0.2
@angular/material-moment-adapter 10.0.2
@ngtools/webpack 9.1.11
@schematics/angular 10.0.2
@schematics/update 0.1000.2
ng-packagr 10.0.1
rxjs 6.6.0
typescript 3.9.6
webpack 4.42.0
我目前正在为提供“插件”框架的monorepository设置而挣扎。
简要描述:我们使用@nrwl/nx工作区来管理整个代码库,其结构看起来有点像这样:
apps/web-ui
apps/mobile-ui
libs/core *
libs/shared *
libs/layout *
libs/feature1
libs/feature2
libs/feature3
ERROR in Failed to compile entry-point @external1/plugin1/shared (es2015 as esm2015) due to compilation errors:
node_modules/@external1/plugin1/fesm2015/plugin1-shared.js:176:29 - error NG2005: The class 'NumberPipe' cannot be created via dependency injection, as it does not have an Angular decorator. This will result in an error at runtime.
Either add the @Injectable() decorator to 'NumberPipe', or configure a different provider (such as a provider with 'useFactory').
176 providers: [NumberPipe, CwaDatePipe],
~~~~~~~~~~
libs/core/src/lib/shared/pipes/number.pipe.ts:16:1
16 @Pipe({
~~~~~~~
17 name: 'cwaNumber',
~~~~~~~~~~~~~~~~~~~~
...
31 }
~~~
32 }
~
'NumberPipe' is declared here.
node_modules/@external1/plugin1/fesm2015/plugin1-shared.js:176:41 - error NG2005: The class 'CwaDatePipe' cannot be created via dependency injection, as it does not have an Angular decorator. This will result in an error at runtime.
Either add the @Injectable() decorator to 'CwaDatePipe', or configure a different provider (such as a provider with 'useFactory').
176 providers: [NumberPipe, CwaDatePipe],
~~~~~~~~~~~
标有*的库是可发布的,使用ng Packager定期构建,并推送到我们的专用npm注册表
除了我们的monorepository工作区之外,还有第二个项目,我们的沙箱。它应该允许外部公司为我们的主项目应用程序开发“插件”,而不必检查工作区(从而控制我们的完整代码库),但仍然能够使用我们的核心和共享组件。他们只需要实现我们核心库的一些接口,还应该能够使用我们的共享组件。只有这样,我们才能控制数字和日期格式、常见域对象的显示等 因此,我创建了第二个nx工作区,并从我们的私有npm注册表安装了预构建的软件包。外部开发人员现在可以基于我们的核心、共享和布局库创建一些新的模块和组件。一旦完成,他们就应该打包他们的库(当然,不必将我们的库绑定到构建结果中,只需将它们声明为对等依赖项!),并将它们发布回我们的npm注册表
根据我们的决定,我们希望引入已完成的模块。不幸的是,这样做失败了,因为Ivy试图用
ngcc
编译node_modules/@external1/plugin1
,当然,在我们的工作区内,这些库不是预先构建的,而是作为源代码在libs文件夹中提供,并通过路径映射使用。我甚至不能改变这一点,因为它会破坏实时重新加载功能(此外,它也不能与预构建的库一起工作(将tsconfig.json中的路径映射从libs/core/src/lib/index.ts
更改为dist/libs/core
等)。此外,我们必须在每次重新编译库时删除node\u modules/@external/@plugin1
中的ivy\u ngcc文件夹,否则,如果我理解正确,它们将以错误的方式链接
我在github上找到了一些描述我问题的票证:
,(