angular - 在 Ionic 和 Angular 应用程序之间共享代码
问题描述
我有一个项目,我有多个 Angular 应用程序和一个离子应用程序。我有许多类(模型)以及可以在所有应用程序之间共享的服务。
我的第一个想法是将共享文件放入他们自己单独的目录/文件夹中并创建一个符号链接。我试图启动离子应用程序,我收到以下信息:
模块构建失败:错误:TypeScript 编译中缺少 /home/norman/Work/vem-shared/shared-services/table/table.service.ts。请通过 'files' 或 'include' 属性确保它在您的 tsconfig 中。
在搜索此错误消息后,我遇到了以下内容,但是,这是针对较低角度的版本(我使用的是 Angular 6 和 Ionic 4)。我还注意到一些关于符号链接在 angular cli 中不起作用的帖子——这似乎是针对旧版本的。
我想知道是否有人知道如何解决这个错误,以及符号链接是否在角度应用程序/离子应用程序中工作?
谢谢
解决方案
对于Angular webapp"preserveSymlinks": true
,通过添加到 angular.json 文件,解决方案似乎非常简单
。
角.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"my-project": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "target",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/showcase/polyfills.ts",
"preserveSymlinks": true,
...
现在,如果您想创建带有保留符号链接的库,那么您必须在中添加相同的功能,tsconfig.lib.json
因为对于库您没有 angular.json
tsconfig.lib.json
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true,
"preserveSymlinks": true },
对于IONIC 应用程序,符号链接问题是一个长期悬而未决的问题,似乎解决方案仍在公开 PR 中。您可以在此处跟踪进度。
推荐阅读
- javascript - 如何在 JavaScript 中添加两个数字?
- javascript - Array(SIZE).fill(1):时间增加 500 倍,内存增加 70 倍,数据增加 10 倍
- reactjs - TypeError:this.props.changeUser 不是函数
- javascript - 图像未显示在服务器上,但在节点 js 中的 localhost 上工作正常
- python - 未正确设置 stderr 是我的程序中缺少输出的原因。除了猜测之外,有没有合适的方法来找出这个原因?
- ruby-on-rails - rails webpacker.yml not found,为什么这会显示在新的设置应用程序中?
- python - 将 json 对象中的特定名称-值对顺序附加到 csv 文件
- rcpp - R::runif() 和 Rcpp::runif() 之间的区别
- python - 如何通过使用 itemgetter 的列表值对字典进行排序?
- python - 如何从我的列表和python中的元组中删除空白引号?