在 index.html 上添加清单 Json
Adding Manifest Json on index.html
我正在尝试在 angular 上实施一个 firebase 通知。但是,当我在 src/ 添加 manifest.json 并在 index.html 中将其引用为 <link rel="manifest" href="./manifest.json">
但是浏览器给我两个错误 404 not found 和
清单:行:1,列:1,语法错误
当我用 dom 检查它并通过新选项卡打开它时,它被重定向到我的索引而不加载资源我已经尝试了一些解决方案并且 none 似乎有效。当我评论索引上的那一行时,错误似乎才消失。
我目前正在使用 angular 版本 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
],
...
}
将 src/manifest.json 添加到 angular.json 中的资产数组
"assets": ["src/assets", "src/favicon.ico", "src/manifest.json"],
重新启动服务器
我正在尝试在 angular 上实施一个 firebase 通知。但是,当我在 src/ 添加 manifest.json 并在 index.html 中将其引用为 <link rel="manifest" href="./manifest.json">
但是浏览器给我两个错误 404 not found 和
清单:行:1,列:1,语法错误
当我用 dom 检查它并通过新选项卡打开它时,它被重定向到我的索引而不加载资源我已经尝试了一些解决方案并且 none 似乎有效。当我评论索引上的那一行时,错误似乎才消失。
我目前正在使用 angular 版本 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
],
...
}
将 src/manifest.json 添加到 angular.json 中的资产数组
"assets": ["src/assets", "src/favicon.ico", "src/manifest.json"],
重新启动服务器