vishal makwana
vishal makwana

Reputation: 11

Angular library asset images are not accessible in consumer app production build

I have an angular library named common-sec in which created assets folder manually under the lib folder. I used images from the assets folder in my library component named "login".

I have used a login component from the common-sec library in my main angular app.

By running the main app with ng serve, library images of assets folder loading perfectly. But when I build my main app using ng build --prod --base-href /prefix/, none of the library images rendered.

I see it tries to request images at localhost:4200/assets/image.png (return 404) But I see images are available at localhost:4200/prefix/assets/image.png

Is it a bug or it's known issue in angular-cli?

Upvotes: 1

Views: 1169

Answers (1)

Yeray
Yeray

Reputation: 1

Are you using an absolute path inside any library component?

Base-href will replace the absolute paths at build time.

The libraries ng build process from AngularCLI doesn't allow --base-href as a parameter, only for projects. So when you apply it to your project build, the libraries are already built (without replacing absolute paths).

You can use your own script to replace them before building the libraries.

Upvotes: 0

Related Questions