在 Angular 库中导入 Markdown 文件
我目前正在尝试在我的 Angular 库中导入 .md(markdown)文件,以便我可以创建一个方法来将自述文件作为字符串传递回任何实现我的库的应用程序。
我已经通过在 src 文件夹中创建一个 global.d.ts 文件并为其提供以下内容,在标准应用程序中实现了此功能:
declare module '*.md';
然后,我可以使用以下命令将 markdown 导入到我的 app.component.ts 文件中:
import * as pageMarkdown from 'raw-loader!../../projects/ui/login/assets/1.md';
这按预期工作。但是,然后我尝试在使用以下方法生成的 Angular 库中执行相同的导入:
ng generate library example-library
如果我随后浏览到该库中的组件打字稿并添加相同的导入,则它不起作用。每当我构建库时,我都会收到以下错误:
找不到模块“raw-loader!../../projects/ui/login/assets/1.md”或其相应的类型声明。
当我将导入添加到库时,它几乎无法获取我的 global.d.ts 中声明的内容。我错过了什么吗?
任何帮助将不胜感激!提前致谢。
I am currently trying to import a .md (markdown) file within my Angular library so I can create a method to pass a readme file as a string back to whatever application implements my library.
I have already got this working in a standard application by creating a global.d.ts file in the src folder and giving it the following content:
declare module '*.md';
I am then able to import the markdown in my app.component.ts file using the following:
import * as pageMarkdown from 'raw-loader!../../projects/ui/login/assets/1.md';
This works as expected. However, I then try to do the same import in an Angular library I have generated using:
ng generate library example-library
If I then browse to the component typescript within that library and add the same import it doesn't work. Whenever I build the library I get the following error:
Cannot find module 'raw-loader!../../projects/ui/login/assets/1.md' or its corresponding type declarations.
Its almost as if it can't pick up whats declared within my global.d.ts when i'm adding the import to a library. Am I missing something?
Any help would be much appreciated! Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您将 markdown 文件放在资产文件夹或文档中,并像资产文件夹一样公开它。这是我创建的一个服务,它使用marked和highlight.js呈现markdown
I recommend you place markdown files in the assets folder or in a docs and expose it like an assets folder. Here is a service i created that renders markdown using marked and highlight.js