【问题标题】:angular custom libraries typing paths are messed up, anything I am doing wrong here?角度自定义库的输入路径搞砸了,我在这里做错了什么吗?
【发布时间】:2019-03-17 09:21:36
【问题描述】:

所以我构建了我的第一个自定义角度库(在幕后使用 ng-packagr)。不幸的是,我构建的库包含到我的本地机器的相对路径,这显然不适用于其他机器。

我创建了一个示例应用程序来测试自定义库。

mya.animations.ts

import {animate, state, style, transition, trigger} from '@angular/animations';


export const FLYOUT_ANIMATIONS = trigger('slideContent', [
  state('void', style({transform: 'translate3d(0, 0, 0)', opacity: 0})),
  state('enter_TOP', style({transform: 'none', opacity: 1})),
  state('leave_TOP', style({transform: 'translate3d(0, -25%, 0)', opacity: 0})),
  transition('* => *', animate(ANIMATION_TIMINGS))
]);

export const CARET_ANIMATIONS = trigger('rotateCaret', [
  state('open', style({transform: 'rotate(180deg)'})),
  state('closed', style({transform: 'rotate(0)'})),
  transition('* => *', animate(ANIMATION_TIMINGS))
]);

因此,在构建时会生成一个名为 mya.animations.d.ts 的文件。不幸的是,其他任何人都无法解决这些路径。

export declare const EXPAND_COLLAPSE_ANIMATIONS: import("../../../../../../../../../../Users/mya/Development/mya-angular-libraries/node_modules/@angular/animations/src/animation_metadata").AnimationTriggerMetadata;

export declare const CARET_ANIMATIONS: import("../../../../../../../../../../Users/mya/Development/mya-angular-libraries/node_modules/@angular/animations/src/animation_metadata").AnimationTriggerMetadata;

在我的组件中,我只是通过

导入这些动画
@Component({
...
animations: [CARET_ANIMATIONS]
...
})

我不确定我在这里做错了什么。非常感谢您的帮助:)

【问题讨论】:

  • 你能展示你的 ng-packagr.json 吗?
  • 那是我的 ng-package.json { "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", "dest": "../../dist/pidx-footer", "lib": { "entryFile": "src/public_api.ts" } }

标签: javascript angular frontend ng-packagr


【解决方案1】:

您在哪里使用这些路径?只需将 sn-p 粘贴到您正在使用的位置即可。

这通常发生在您使用在构造函数之外定义的变量时。

【讨论】:

  • 所以在我的 mya.animations.ts 中我声明了动画触发器并导出它们。在我的组件中,我导入它并将其添加到组件装饰器中,如上面的问题所示。
  • 我需要你在哪里输入这个动画文件和你正在使用的地方的代码。对于其他一些代码,我在我的库中也遇到了这个问题
  • 感谢您的帮助!当然。希望这是您想知道的 => 在我的组件中,我导入动画 import {CARET_ANIMATIONS} from './mya.animations'; 然后通过 <span class="icon icon--arrow-down-thin navigation-footer__icon" [@rotateCaret]="navigationSection.animationState"></span> 将其添加到 HTMLElement 我然后为组件中的 navigationSection 设置动画状态,例如navgationSections[0].animationState = 'closed'我没有在我的代码中的任何其他地方使用 CARET_ANIMATIONS。
  • navigationSection声明和定义,我想在你导入import {CARET_ANIMATIONS} from './mya.animations';的文件中看到
  • 如果我只是内联这些动画而不是先将它们分配给 const,则不会将任何内容添加到 .d.ts 文件中。可能是因为装饰器是在元数据文件中处理的
猜你喜欢
  • 2018-10-26
  • 2012-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-17
  • 1970-01-01
相关资源
最近更新 更多