简体   繁体   中英

Angular Service worker (ngsw-worker.js) is not generated in the "/dist" folder after running build command

I'm checking an NX project to see if the service worker is performing as planned. After running "ng build appname," I have a problem in that the Angular Service worker is not generated in the "/dist" folder. What can I do to fix this?

Imported in the app.module as should below

// PWA
ServiceWorkerModule.register('ngsw-worker.js', { 
  enabled:true,
  // Register the ServiceWorker as soon as the app is stable
  // or after 30 seconds (whichever comes first).
  registrationStrategy: 'registerWhenStable:30000',
  // registrationStrategy: 'registerImmediately' 
}),

I resolved the issue by adding the following in the package.json.

script
{
"ngsw-config": "node_modules/.bin/ngsw-config dist src/ngsw-config.json",
"ngsw-copy": "cp node_modules/@angular/service-worker/ngsw-worker.js dist/",
"build-prod-ngsw": "ng build --prod && npm run ngsw-config && npm run ngsw-copy",
"serve-prod-ngsw": "npm run build-prod-ngsw && http-server dist -p 8080"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM