0

The issue is the path of the image located in "assets" folder is not loading after ng build.

I am running ng build after changing the path to <base href="/skstose/"> of index.html.

Dev environment means ng serve. Prod environment means ng build after compiling.

1) The below issue is in dev environment:-

Module Error (from ./node_modules/postcss-loader/src/index.js):
(Emitted value instead of an instance of Error) CssSyntaxError:
Can't resolve 'assets/images/skistose/kgExtract.png' in 'E:\Workspace\skistose\src\app\skistose-kg-extract'

> 2 |   background: url("assets/images/skillStore/kgExtract.png") no-repeat;
                    ^

2) The below issue is in prod environment:-

.css

.bg{
    background: url(/assets/images/skillStore/kgExtract.png) no-repeat
}

is working in dev environement but not in prod environment.

.css

.bg{
    background: url(assets/images/skillStore/kgExtract.png) no-repeat
   }

is working in prod environment but not in dev environment.

However, <img src="assets/images/skillStore/uploadFile.png"> is working fine in dev environment as well as 'prod environment'.

In dev environment ,

 <base href="/">

In prod build:-

 <base href="/skstose/">

3 Answers 3

2

Dont edit in index html;

for building in url try this code:-

ng build --prod --base-href='/skstose/'

Url link will be open like this 'http:/test.com/skstose'

Here is the resources:- https://angular.io/guide/deployment

Sign up to request clarification or add additional context in comments.

7 Comments

still same issue
url path will be same "url(assets/images/skillStore/kgExtract.png) no-repeat" just build with ng build --prod --base-href='/skstose/'
but in dev environment ng serve, its not loading image.
in dev server what did u put ur url path ?
background: url(/assets/images/skillStore/kgExtract.png) no-repeat ... this is working but background: url(assets/images/skillStore/kgExtract.png) no-repeat not working.
|
0

Are you getting assets folder after ng build in your dist folder?

if not try with ng build --prod and check

1 Comment

I am just trying for ng build and changing the path to <base href="/skstose/"> of index.html. When inspecting image on google chrome dev tool , the issue I found.
0

Your file "index.html" must contain:

<base href="/">

Try searching for your image this way

background-image: url(../../../../../assets/My-image_2020.jpg);

And build your project whit

ng build --prod --base-href /skstose/

The end result(compiled) is in charge of giving context to your files

PD: to work locally it is not necessary to change the path in <base href="/"> of index.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.