问题
"@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
回答1:
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
回答2:
Don't use /
before assets
background: url("assets/images/vector-icon.png") no-repeat 25%;
PS. And the assets/images
folder has to contain this image.
PPS. Make sure this path is correct.
回答3:
Faced this problem myself. Instead of /assets...
, use src/assets...
. Make sure you don't put /
before src
.
回答4:
First thing you need to check that go to assets folder and check that file exists or not. If file exists, try below line
background: url('./assets/images/vector-icon.png') no-repeat 25%;
回答5:
Try this:
background: url("/src/assets/images/vector-icon.png") no-repeat 25%;
来源:https://stackoverflow.com/questions/56625979/ng-build-base-href-deploy-url-css-background-image-not-worki