angular 6、构建无法在Firebase托管上加载图片
angular 6, build can't load images on Firebase hosting
将 angular 应用程序部署到 firebase 托管后,我无法从资产文件夹加载图像。 (构建——产品)
当 运行 在本地主机上显示图像时。
所有其他东西都正确加载。
这是我的包裹 json
cli: ~6.2.0-beta.2
firebase 工具: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">
none 本作品。
在 firebase.json
的托管设置
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]}
firebase 有什么技巧吗?重写?有人可以帮助我!
firebase 部署后 angular 6.1.3 中的资产现在正在加载图像!终于找到了解决方案,它对我有用。问题是 tsconfig.json 更改:
"outDir": "./dist/out-tsc",
至:
"outDir": "./dist",
我在部署到 Firebase 托管后遇到了与静态资产相同的问题,尽管它们在从本地主机提供服务时工作正常。我不得不从
<img src="/src/assets/img/pricing_comparison.PNG">
至
<img src="/assets/img/pricing_comparison.PNG">
.
(p.s。我尝试根据已接受的答案更改我的 tsconfig.json 文件,但这并没有更改或解决我的错误)
我也遇到了同样的问题。这是我试过的解决方案
打开tsconfig.json更改:
"outDir": "./dist/out-tsc"
,
至:
"outDir": "./dist"
打开angular.json。确保资产配置如下
"assets": [
"src/favicon.ico",
"src/assets"
],
- 更改 img 标签
<br>
src="/src/assets/img/pricing_comparison.PNG"
至 <br>
src="/assets/img/pricing_comparison.PNG"
.
如果您在本地工作
只需像
一样使用 url
#login {
background-image: url('/assets/app-assets/img/gallery/login-bg.jpg');
background-size: 100% 100%;
background-repeat: no-repeat;
}
在您的 CSS 或 html 组件中,这对我有用。
只需将图像 url 从 /src/assets/your_image.png
更改为 /assets/your_image.png
这是我的 angular 版本
Angular CLI: 8.2.2
Node: 12.8.0
OS: darwin x64
Angular: 8.2.12
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.802.2
@angular-devkit/build-angular 0.802.2
@angular-devkit/build-optimizer 0.802.2
@angular-devkit/build-webpack 0.802.2
@angular-devkit/core 8.2.2
@angular-devkit/schematics 8.2.2
@angular/cli 8.2.2
@ngtools/webpack 8.2.2
@schematics/angular 8.2.2
@schematics/update 0.802.2
rxjs 6.4.0
typescript 3.5.3
webpack 4.38.0
将 angular 应用程序部署到 firebase 托管后,我无法从资产文件夹加载图像。 (构建——产品) 当 运行 在本地主机上显示图像时。 所有其他东西都正确加载。 这是我的包裹 json cli: ~6.2.0-beta.2 firebase 工具: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">
none 本作品。
在 firebase.json
的托管设置"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]}
firebase 有什么技巧吗?重写?有人可以帮助我!
firebase 部署后 angular 6.1.3 中的资产现在正在加载图像!终于找到了解决方案,它对我有用。问题是 tsconfig.json 更改:
"outDir": "./dist/out-tsc",
至:
"outDir": "./dist",
我在部署到 Firebase 托管后遇到了与静态资产相同的问题,尽管它们在从本地主机提供服务时工作正常。我不得不从
<img src="/src/assets/img/pricing_comparison.PNG">
至
<img src="/assets/img/pricing_comparison.PNG">
.
(p.s。我尝试根据已接受的答案更改我的 tsconfig.json 文件,但这并没有更改或解决我的错误)
我也遇到了同样的问题。这是我试过的解决方案
打开tsconfig.json更改:
"outDir": "./dist/out-tsc"
,至:
"outDir": "./dist"
打开angular.json。确保资产配置如下
"assets": [
"src/favicon.ico",
"src/assets"
],
- 更改 img 标签
<br>
src="/src/assets/img/pricing_comparison.PNG"
至<br>
src="/assets/img/pricing_comparison.PNG"
.
如果您在本地工作
只需像
一样使用 url#login {
background-image: url('/assets/app-assets/img/gallery/login-bg.jpg');
background-size: 100% 100%;
background-repeat: no-repeat;
}
在您的 CSS 或 html 组件中,这对我有用。
只需将图像 url 从 /src/assets/your_image.png
更改为 /assets/your_image.png
这是我的 angular 版本
Angular CLI: 8.2.2
Node: 12.8.0
OS: darwin x64
Angular: 8.2.12
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.802.2
@angular-devkit/build-angular 0.802.2
@angular-devkit/build-optimizer 0.802.2
@angular-devkit/build-webpack 0.802.2
@angular-devkit/core 8.2.2
@angular-devkit/schematics 8.2.2
@angular/cli 8.2.2
@ngtools/webpack 8.2.2
@schematics/angular 8.2.2
@schematics/update 0.802.2
rxjs 6.4.0
typescript 3.5.3
webpack 4.38.0