I'm unable to load images from the assets folder after deploy the angular app to firebase hosting. (build --prod) when run on localhost the images show. All other things are loading properly. this is my package json cli: ~6.2.0-beta.2 firebase-tools: 4.1.0
{
"name": "protocols",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"deploy": "ng build --prod && firebase deploy"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.2",
"@angular/cdk": "^6.4.5",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/material": "^6.4.5",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/pwa": "^0.8.0-beta.2",
"@angular/router": "^6.1.0",
"@angular/service-worker": "^6.1.0",
"angularfire2": "^5.0.0-rc.11",
"core-js": "^2.5.4",
"firebase": "^5.3.1",
"hammerjs": "^2.0.8",
"mat-progress-buttons": "^6.0.1",
"rxjs": "^6.0.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.8.0-beta.0",
"@angular/cli": "~6.2.0-beta.2",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.3.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~2.9.2"
}
}
tried at appComponent
<img src="../assets/image.jpg">
<img src="/assets/image.jpg">
<img src="assets/image.jpg">
none of this work.
hosting settings at firebase.json
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
Are there some trick on the firebase? rewrites? someone can help me!
Images loading now from assets in angular 6.1.3 after firebase deploy! Found the solution finally, well it works for me. The issue is the tsconfig.json change:
to:
I had the same problem with static assets after deploying to Firebase hosting, even though they worked fine when serving from localhost. I had to change from
<img src="/src/assets/img/pricing_comparison.PNG">
to<img src="/assets/img/pricing_comparison.PNG">
.(p.s. I tried changing my tsconfig.json file according to the accepted answer, but this didn't change or resolve my error)
I also had the same issue. Here is the solution i tried
Open tsconfig.json change:
"outDir": "./dist/out-tsc"
,to:
"outDir": "./dist"
Open angular.json. make sure assets configurations are as like below
<br>
src="/src/assets/img/pricing_comparison.PNG"
to<br>
src="/assets/img/pricing_comparison.PNG"
.