Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular copies images to its root folder

Tags:

angular

I keep my assets images under 'assets/images/icons' folder and in my style.scss file I have rules like 'background: url(assets/images/icons/searchbox_magnifier.png) no-repeat #f5f5f5;' but while making a production build, Angular is coping all those files to its root folder and changing style.scss rules according to it, like 'background: url(searchbox_magnifier.png)', see the images attached.

style.scss production build

How to avoid the issue?

like image 807
Angry Beaver Avatar asked Jul 03 '18 09:07

Angry Beaver


2 Answers

I had the same problem. It is solved simply by changing the paths from relative to absolute.
For example,
background-image: url("../../../assets/images/background.svg")
or
background-image: url("~src/assets/images/background.svg")

replace with
background-image: url("/assets/images/background.svg").

It will solve your problem

like image 175
Alexander Gvozd Avatar answered Sep 22 '22 00:09

Alexander Gvozd


I was facing the same issue. Images from assets folder, if used as relative paths in the CSS files, are COPIED to the root of the dest build.

if the path in the CSS is absolute, it does not. using absolute path solved the problem for @angry beaver , only because his application is deployed into the root folder of his web-server.

please note, that if you use --base-href in your build, it will append it to the url inside the CSS files. thus making it a problem for doing a build that needs to be deployed to different destinations (qa/pre-prod etc) if each one is in another sub-folder (for example, qa is in the root folder, and production is in a subfolder)

like image 45
May Avatar answered Sep 19 '22 00:09

May