在Angular库中保留符号链接

24

我有一个问题。

我正在尝试使用ng-cli创建一个Angular 8库,但是我无法通过npm link保留来自外部应用程序的符号链接。

我尝试在我的angular.json文件中添加以下内容:

    "build": {
      "builder": "@angular-devkit/build-ng-packagr:build",
      "options": {
        "preserveSymlinks": true,
        "tsConfig": "projects/button/tsconfig.lib.json",
        "project": "projects/button/ng-package.json"
      }
    }, 

但是得到了:

"Schema validation failed with the following errors: Data path ""
should NOT have additional properties(preserveSymlinks)."

我发现它对于库并没有起作用。

然后我尝试将这个添加到我的tsconfig.lib.json文件中:

 "angularCompilerOptions": {
    "annotateForClosureCompiler": true,
    "skipTemplateCodegen": true,
    "strictMetadataEmit": true,
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true,
    "enableResourceInlining": true,
    "preserveSymlinks": true
  }

什么也没有发生。

我在这里寻找解决方案,但没有找到类似的内容。

我该如何做呢?

谢谢!


1
如果在使用库的应用程序的 tsconfig.json 文件中添加 "preserveSymlinks": true,会有什么区别吗? - R. Richards
@R.Richards 我在 Git 上的这个问题中看到了这个:https://github.com/angular/angular/issues/31989#issuecomment-523375803 - andersonbalves
我需要这个,因为当我在我的外部应用程序中使用我的组件(在库内)时,我会遇到以下错误:NgBradButtonComponent.html:2 ERROR NullInjectorError: StaticInjectorError(AppModule)[NgClassImpl -> ElementRef]: StaticInjectorError(Platform: core)[NgClassImpl -> ElementRef]: 原因是我的组件具有_ngClass_和_ngIf_。我不知道这是否是正确的方法。 - andersonbalves
我能理解你为什么需要它,这很有道理。我希望在使用的应用程序中添加它会起作用。希望有人会发布一个答案。 - R. Richards
1
@andersonbalves,你找到解决方案了吗?我也遇到了同样的问题。 - Ashwani Kumar
4个回答

30

4
在 Angular 13 中,这使我能够使用符号链接与 ng serve 一起使用。

enter image description here


3

将以下内容添加到我的tsconfig.lib.json中,这对我很有效:

 "angularCompilerOptions": {
    "preserveSymlinks": true
  }

你确定在 tsconfig.lib.prod.json 中没有覆盖此属性并进行生产构建吗?


0
对我来说,将以下代码段添加到ng-packagr库的tsconfig.json文件中是有效的:
{
  "compilerOptions": {
    "paths": {
      "@angular/*": [ "./node_modules/@angular/*" ]
    }
  }
}

设置:Angular 14,ng-packagr 14.2.2

你能进一步解释一下吗?我以前没有见过这个。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接