将angular应用程序部署到firebase托管后,我无法从assets文件夹加载图像. (build –prod)
当在localhost上运行时,图像显示.
所有其他东西都正确加载.
这是我的包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"
}
}
在appComponent上尝试过
<img src="../assets/image.jpg">
<img src="/assets/image.jpg">
<img src="assets/image.jpg">
这一切都没有.
在firebase.json托管设置
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
在firebase上有一些技巧吗?重写?有人可以帮助我!
最佳答案 在firebase部署之后,现在从角度6.1.3中的资产加载图像!终于找到了解决方案,它对我有用.问题是tsconfig.json更改:
"outDir": "./dist/out-tsc",
至:
"outDir": "./dist",