这是我第一次与服务人员一起工作,我遇到了困难,因为我总是在网络 - 应用程序 - 清单选项卡中遇到此错误:
一些技术细节:
包.json
"@angular/animations": "~9.1.0",
"@angular/common": "~9.1.0",
"@angular/compiler": "~9.1.0",
"@angular/core": "~9.1.0",
"@angular/forms": "~9.1.0",
"@angular/localize": "~9.1.0",
"@angular/platform-browser": "~9.1.0",
"@angular/platform-browser-dynamic": "~9.1.0",
"@angular/pwa": "^0.901.12",
"@angular/router": "~9.1.0",
"@angular/service-worker": "~9.1.0",
角.json
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "projects/appName/src/environments/environment.ts",
"with": "projects/appName/src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "5mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
],
"serviceWorker": true,
"ngswConfigPath": "projects/appName/src/ngsw-config.json"
manifest.webmanifest
{
"name": "app name",
"short_name": "app",
"description": "test test",
"theme_color": "#003f8b",
"background_color": "#ffffff",
"display": "standalone",
"orientation": "portrait",
"scope": "/",
"start_url": "/",
"icons": [
{
"src": "favicon.ico",
"sizes": "16x16",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/flatwork.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/icon-withdrawal-mark.png",
"sizes": "27x23",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/incoming.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/input.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/master_data_icon.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/outgoing.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/output.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/rental_outfit.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/repair.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/scanned_on.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
},
{
"src": "assets/images/icons/tooltip_icon.svg",
"sizes": "150x150",
"type": "image/png",
"purpose": "any"
}
]
}
索引.html
<meta name="theme-color" content="#003f8b" />
<link rel="manifest" href="manifest.webmanifest" />
<body>
<bar-root></bar-root>
<noscript
>Please enable JavaScript to continue using this application.</noscript
>
</body>
应用程序模块
imports: [
BrowserModule,
ServiceWorkerModule.register('../ngsw-worker.js', {
enabled: environment.production
}),
... // other imports
],
providers: [
{
provide: SwRegistrationOptions,
useFactory: () => ({
enabled: environment.production,
registrationStrategy: 'registerImmediately',
}),
},
]
ngsw-config.json
{
"$schema": "../../../node_modules/@angular/service-worker/config/schema.json",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/manifest.webmanifest",
"/*.css",
"/*.js"
]
}
},
{
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
]
}
}
]
}
此外,这是检查路径导入的项目结构:
我错过了什么?另外,测试任何配置更改的最佳方法是什么?