Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng build --base-href="/.../" --deploy-url="/.../" css background image not working

"@angular/core": "~8.0.0",

scaffold angular 8 project with scss style option

i have code for as mentioned below in component scss file

background: url("/assets/images/vector-icon.png") no-repeat 25%;

at the final buil using command

ng build --prod --base-href="/website/" --deploy-url="/website/"

put build at sub folder root/webside

everything working fine except background image path

i have tried by ip/website/assets/images/vector-icon.png at that point i am able to get image.

What if i don't wont to change the path at every css file.

any help would be appreciated. thanks in advance

like image 727
paras shah Avatar asked Nov 30 '22 13:11

paras shah


1 Answers

The solution is to put "rebaseRootRelativeCssUrls": true in the angular.json file.

The / before assets is correct.( url(/assets/img...) )

 "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
           ...
           "rebaseRootRelativeCssUrls": true

like image 165
BearZon Avatar answered Dec 31 '22 03:12

BearZon