将导入的 angular 应用程序中的库用于多项目结构
Use a library in an imported angular application into multi-project structure
我在 10.0.6
中有一个 angular 应用程序 a-app
,但我需要将其包含到 angular 多项目结构中。在这个多项目结构中,我有一个 b-app
应用程序。
- Angular 多项目结构运行良好。
- 我创建了一个
my-lib
库并将其包含在 b-app
应用程序中并且它正在运行。我按照这个程序 Using your own library in applications
- 我将我的
a-app
应用程序移动到多项目结构中,它正在运行!为了完成这项工作,我使用了多项目结构中的 package.json
、tsconfig.json
、tsconfig.base.json
、angular.json
。 tsconfig.app.json
和 tsconfig.spec.json
扩展 ../../tsconfig.base.json
.
- 这意味着,我可以 运行 应用程序
a-app
和 b-app
来自多项目结构。
文件夹结构是这样的:
my-workspace/
... (workspace-wide config files)
projects/ (generated applications and libraries)
a-app/ --(imported application manually)
... --(application-specific config: karma.conf.js, tsconfig.app.json, tsconfig.spec.json)
src/ --(source and support files for application)
b-app/ --(an explicitly generated application)
... --(application-specific config)
src/ --(source and support files for application)
my-lib/ --(a generated library)
... --(library-specific config)
src/ --source and support files for library)
但是当我尝试在多项目结构中的应用程序 a-app
中导入 my-lib
时,它不起作用!!!仅显示此错误:
Cannot find module 'my-lib' or its corresponding type declarations
我已将 a-app
中的所有配置文件修改为与 b-app
相似,将 a-app
包含在 angular.json
中,但仍然无法正常工作。实际上,我从这里执行了步骤 3-5:
我在此配置中缺少什么才能使其正常工作?
嗯...这是一个错误。
我在 a-app
应用程序中使用 Path mapping 这意味着我已经在 a-app
中的 tsconfig.app.json
中配置了 paths
属性 .
使用该配置,a-app
没有扩展 tsconfig.base.json
中的 paths
属性,因此找不到 my-lib
在此文件上声明的路径。
解决方案:remove/check tsconfig.app.json
中 paths
中的任何配置以正确扩展 tsconfig.base.json
my-workspace/
tsconfig.base.json <--- this file contains all libraries declared
projects/
a-app/
tsconfig.app.json <--- Check this file in order to extend properly the tsconfig.base.json
b-app/
tsconfig.app.json
my-lib/
...
src/
我在 10.0.6
中有一个 angular 应用程序 a-app
,但我需要将其包含到 angular 多项目结构中。在这个多项目结构中,我有一个 b-app
应用程序。
- Angular 多项目结构运行良好。
- 我创建了一个
my-lib
库并将其包含在b-app
应用程序中并且它正在运行。我按照这个程序 Using your own library in applications - 我将我的
a-app
应用程序移动到多项目结构中,它正在运行!为了完成这项工作,我使用了多项目结构中的package.json
、tsconfig.json
、tsconfig.base.json
、angular.json
。tsconfig.app.json
和tsconfig.spec.json
扩展../../tsconfig.base.json
. - 这意味着,我可以 运行 应用程序
a-app
和b-app
来自多项目结构。
文件夹结构是这样的:
my-workspace/
... (workspace-wide config files)
projects/ (generated applications and libraries)
a-app/ --(imported application manually)
... --(application-specific config: karma.conf.js, tsconfig.app.json, tsconfig.spec.json)
src/ --(source and support files for application)
b-app/ --(an explicitly generated application)
... --(application-specific config)
src/ --(source and support files for application)
my-lib/ --(a generated library)
... --(library-specific config)
src/ --source and support files for library)
但是当我尝试在多项目结构中的应用程序 a-app
中导入 my-lib
时,它不起作用!!!仅显示此错误:
Cannot find module 'my-lib' or its corresponding type declarations
我已将 a-app
中的所有配置文件修改为与 b-app
相似,将 a-app
包含在 angular.json
中,但仍然无法正常工作。实际上,我从这里执行了步骤 3-5:
我在此配置中缺少什么才能使其正常工作?
嗯...这是一个错误。
我在 a-app
应用程序中使用 Path mapping 这意味着我已经在 a-app
中的 tsconfig.app.json
中配置了 paths
属性 .
使用该配置,a-app
没有扩展 tsconfig.base.json
中的 paths
属性,因此找不到 my-lib
在此文件上声明的路径。
解决方案:remove/check tsconfig.app.json
中 paths
中的任何配置以正确扩展 tsconfig.base.json
my-workspace/
tsconfig.base.json <--- this file contains all libraries declared
projects/
a-app/
tsconfig.app.json <--- Check this file in order to extend properly the tsconfig.base.json
b-app/
tsconfig.app.json
my-lib/
...
src/