Importing a markdown file within an Angular library

Discussão em 'Angular' iniciado por Charlie Stuart, Fevereiro 10, 2025.

  1. 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.

    Continue reading...

Compartilhe esta Página