在index.html上添加Manifest Json



我正在尝试在angular上实现一个firebase通知。然而,当我在src/中添加manifest.json并在index.html中将其引用为<link rel="manifest" href="./manifest.json">时但是浏览器给了我两个错误404没有找到清单:行:1,列:1,语法错误当我用dom检查它并通过一个新的选项卡打开它时,它被重定向到我的索引,而没有加载资源。我尝试了一些解决方案,但似乎都不起作用。只有当我评论索引上的那一行时,这个错误似乎才会消失。我目前使用的是角度版本7.1.0


angular.json

{

"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"Ang7": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
},

"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/Ang7",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets",
"src/manifest.json"
],
"styles": [
"src/assets/css/w3.scss",
"node_modules/ngx-toastr/toastr.css",
"src/assets/css/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "Ang7:build"
},
"configurations": {
"production": {
"browserTarget": "Ang7:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "Ang7:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"src/styles.scss"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},

"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},

"Ang7-e2e": {
"root": "e2e/",
"projectType": "application",
"prefix": "",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "Ang7:serve"
},
"configurations": {
"production": {
"devServerTarget": "Ang7:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "Ang7",
"cli": {
"analytics": "2655066d-910d-4521-b978-37a981395ab1"
}
}

manifest.json

{
"gcmsender_id":"654616556484"
}

似乎错过了将其添加到angular.json文件中。

确保angular.json结构包含manifest.json文件。

{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"project-name": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
...
"assets": [
"src/assets",
"src/favicon.ico",
"manifest.json"  // <-- Must be included
],
...
}
  1. 将src/manifest.json添加到angular.json中的资产数组中"assets": ["src/assets", "src/favicon.ico", "src/manifest.json"],

  2. 重新启动服务器

相关内容

  • 没有找到相关文章

最新更新