angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Assets not found in scss/css when using base-href

Open maxpfandl opened this issue 9 years ago • 26 comments

Please provide us with the following information:

OS?

Windows 10 x64

Versions.

@angular/cli: 1.0.0-beta.32.3 [1.0.0-beta.28.3] node: 7.2.0 os: win32 x64 @angular/common: 2.4.7 @angular/compiler: 2.4.7 @angular/core: 2.4.7 @angular/forms: 2.4.7 @angular/http: 2.4.7 @angular/platform-browser: 2.4.7 @angular/platform-browser-dynamic: 2.4.7 @angular/router: 3.4.7 @angular/cli: 1.0.0-beta.32.3 @angular/compiler-cli: 2.4.7

Repro steps.

create an app with ng-cli. create a build for a server (not ng serve) with base-href set to xxx. use url's in scss (like background-image: url('/assets/img/myimg'). the imagepath for the url will be set to server/assets/img/myimg instead of server/xxx/assets/img/myimg. If I try to use a relative path in the scss (ie url('./assets/img/myimg') ) i get a compileerror, that this is not resolveable. If i try to use url('assets/img/myimg') this is also not resolveable for the compiler. my .angular-cli.json has this section: "assets": [ "assets", "favicon.ico" ],

The log given by the failure.

There is only a compileerror that the path is not resolveable or a runtime 404 when the resource is not found without using the base-ref in the url.

Mention any other details that might be useful.

There is a workaround for this issue: i set the style in my component directly and inject it like this: <span ... [style.background-image]="getLogo()">

getLogo() { return this._domSanitizer.bypassSecurityTrustStyle(url(${this.logosrc}); }

where logosrc = "./assets/img/myimg"


Thanks! We'll be in touch soon.

maxpfandl avatar Feb 17 '17 13:02 maxpfandl

Looks like some of the webpack-isms work for this issue too, ie url('~../src/assets/foo.svg') worked for me

the-destro avatar Sep 21 '18 19:09 the-destro

Looks like some of the webpack-isms work for this issue too, ie url('~../src/assets/foo.svg') worked for me

@the-destro What about the JS and CSS resources, once ng build is responsible for link then on index.html?

ghost avatar Sep 21 '18 20:09 ghost

Same problem than @Gil-Epshtain

WizardPC avatar Dec 13 '18 17:12 WizardPC

In my case url("~src/assets/foo.svg") worked. As I see, every case is different ;).

lukaszmn avatar Dec 19 '18 14:12 lukaszmn

In my case it was : src: url('~../src/assets/fonts/icomoon.eot?9ng3yy');

But i have remaining issue with fontawesome dependencie...

Failed to decode downloaded font: http://.....:8080/w8mcnt/fontawesome-webfont.af7ae505a9eed503f8b8.woff2?v=4.7.0
OTS parsing error: invalid version tag

So i have square instead of icon. Link in the console worked. Any fix ?

WizardPC avatar Dec 24 '18 09:12 WizardPC

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.