带有自定义Angular库和NPM链接的Storybook中找不到组件templateUrl和stylesUrl

问题描述

我正在尝试创建一个新的Angular 10库和一个单独的Storybook,因为它是文档和开发视图。当html和样式在* .component.ts文件中内联时,一切都会按预期进行。但是,每当我尝试使用单独的html和scss文件创建新组件时,Storybook都会在控制台中出现错误,提示找不到 .component.html / .component.scss。

复制步骤

创建一个新库

ng new my-workspace --create-application=false
cd my-workspace
ng generate library my-lib
ng generate component notification --project=my-lib

这将生成具有以下设置的组件:

  selector: 'lib-notification',templateUrl: './notification.component.html',styleUrls: ['./notification.component.scss']
})
export class Notification

接下来我要做的是构建库,将CD光盘安装到dist/my-lib文件夹中,然后运行npm link

我还创建了另一个将包含Storybook项目的Angular项目,我按照本教程开始了它:https://www.learnstorybook.com/intro-to-storybook/angular/en/get-started/

完成本教程后,我使用npm link my-lib将我先前构建的库添加到了故事书项目中,并为此在/src/stories中创建了一个新的故事文件。之后,我将组件导入到故事文件中,例如import { NotificationComponent } from 'my-lib';,看起来一切都很好,因为它可以在链接的npm包中找到正确的组件。

但是每当我运行Storybook npm run storybook时,都会出现以下错误,因为它找不到正确的templateUrl和styleUrl:

GET http://localhost:6006/notification.component.html 404 (Not Found)

zone.js:690 Unhandled Promise rejection: Failed to load notification.component.html ; Zone: <root> ; Task: Promise.then ; Value: Failed to load notification.component.html undefined

现在,我想知道是否可以分隔html / scss / ts文件,因为出于可读性考虑,我希望这样做。如果可行,如何确保运行Storybook时组件的根目录不是./?我应该添加某种Webpack配置还是其他解决方案?

如果不清楚,请随时提出,我将尽力提供尽可能多的信息。

谢谢您的问候

卫斯理

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)