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

paras shah picture paras shah · Jun 17, 2019 · Viewed 7.8k times · Source

"@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

Answer

BearZon picture BearZon · Nov 27, 2019

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