5

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

5 Answers 5

13

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 
Sign up to request clarification or add additional context in comments.

3 Comments

This issue arose for us when upgrading from Angular 6 to 8. Adding this in the build options, fixed it. Thanks!
rebaseRootRelativeCssUrls is deprecated and will be removed in the next major release. Reference: angular.io/cli/build
@curiousBoy What would replace it? Because this functionality is needed, apps simply don't work without this rebasing
5

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.

9 Comments

getting this error (Emitted value instead of an instance of Error) CssSyntaxError:
@parasshah does your assets/images folder contain this vector-icon.png file actually at the time of building?
@parasshah I asked, because you have to see this error, in case an image doesn't exist or a path is incorrect.
@Don_Toamto yes you are right at same path image is exists and it is working at loca host
but how can i overcome the compilation error due to whic i am not able to build my project
|
1

Faced this problem myself. Instead of /assets..., use src/assets.... Make sure you don't put / before src.

1 Comment

This add a copy of your image in your root of dist folder,
0

Try this:

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

Comments

-1

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%; 

1 Comment

getting same compilation error (Emitted value instead of an instance of Error) CssSyntaxError:

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.