Assets not found in scss/css when using base-href
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.
Looks like some of the webpack-isms work for this issue too, ie url('~../src/assets/foo.svg') worked for me
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?
Same problem than @Gil-Epshtain
In my case url("~src/assets/foo.svg") worked. As I see, every case is different ;).
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 ?
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.