Search code examples
angularshared-librariesng-packagr

Include assets when building library using ng-packagr


Could anyone give a hint where to start to include images and css files into Angular library using ng-packagr?


Solution

  • There's an official issue for that question here. It's actually quite simple to include images and the like to your library: You can just copy them to the dist folder manually after ng-packagr has done its thing.

    However, it's more difficult to automate the extraction of those files in projects that'll use your library. In the issue referenced above BenjaminDobler suggests to add the following mapping to the .angular-cli.json file of any consumer project:

    { "glob": "**/*", "input": "../node_modules/my-lib/assets", "output": "./assets/my-lib/" }
    

    I feel this is more of an NPM issue, though, and there also are bare NPM solutions for it like pkg-assets and npm-assets.