Angular CLI >= 1.6.0 (Otherwise, you can do manually, but bellow version are not stable)
Angular >= 5.0.0 or later
ng new PROJECT-NAME --service-worker (or using the alias — -sw )
# src/app/app.module.ts
...
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
@NgModule({
...
imports: [
...
ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })
],
...
})
export class AppModule { }
# .angular-cli.json added property
apps.serviceWorker=true