How to require assets in a library
See original GitHub issueType of Issue
[ ] Bug Report
[x] Feature Request
Description
Many components of my library uses SVGs (icons, various illustrations, etc).
Until version 9 I simply required them in the component :
const imagePath = require('./assets/images/404.svg');
// used with [src] or a component that takes an url input
This worked by copying my assets folder inside dist/fesm5 before publishing. There where no error or warning while building the library and the application builded fine as well.
Now with Angular 9 and the latest version of ng-packr this no longer works. This error happens when building the library :
ERROR: Could not resolve ‘./assets/images/404.svg’ from dist/esm2015/components/core/not-found/not-found.component.js
I understand that there is a new official option for handling assets but this seems to only cover assets exposed by a library and used by an application.
What about assets used by the library itself ?
Version Information
$ node_modules/.bin/ng-packagr --version
ng-packagr: 9.1.1
@angular/*: 9.1.2
typescript: 3.8.3
rxjs: 6.5.5
node: 10.16.2
yarn: 1.22.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:13 (2 by maintainers)
Top Results From Across the Web
Include assets when building angular library - Stack Overflow
I've tried multiple solutions like adding the assets array in angular.json and copying the assets folder to the created dist folder. I am...
Read more >Set up an Asset Library to store image, audio, or video files
Under Apps you can add, click Asset Library. In the Adding Asset Library dialog box, type a name for the library, and then...
Read more >Lessons learned on including library assets into Angular ...
How to include assets used by libraries · Assets should exist only once, preferably in the project that utilizes them. · An update...
Read more >Manage assets with the Library - Google Web Designer Help
Add assets to the Library. There are several ways to import assets: Drag the assets from your computer into the Google Web Designer...
Read more >Creating an Easy-to-Navigate Asset Library - Stacks
The same golden rule applies to digital asset libraries where organization's store their valuable images, videos, design files, and branding ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You should inline your assets in components css file and from the template use a class.
https://github.com/ng-packagr/ng-packagr/blob/master/docs/embed-assets-css.md
requiring
an image is a webpack specific feature, and is not supported by the Angular CLI see https://github.com/angular/angular-cli/issues/17400#issuecomment-609744000This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
This action has been performed automatically by a bot.