question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to require assets in a library

See original GitHub issue

Type 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
alan-agius4commented, May 11, 2020

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-609744000

0reactions
github-actions[bot]commented, Jul 13, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found