Angular-cli: Feature: ServiceWorker support in CLI

Created on 13 Jan 2017  路  15Comments  路  Source: angular/angular-cli

Requested by @alxhub.

This is non 1.0 blocking but will be tracked in the 1.0.

2 (required)

Most helpful comment

For reference for anyone who wants to use service workers with the CLI now its not to much work using the sw-precache library. I have a blog post and working demo here. https://coryrylan.com/blog/fast-offline-angular-apps-with-service-workers

All 15 comments

For reference for anyone who wants to use service workers with the CLI now its not to much work using the sw-precache library. I have a blog post and working demo here. https://coryrylan.com/blog/fast-offline-angular-apps-with-service-workers

@hansl I notice that this is marked Done in Tracking and I see @alxhub branch here https://github.com/alxhub/angular-cli/tree/sw-support do you have an idea of when this might get a PR? I know you guys are really busy and you are doing a great job, I only ask because I was thinking of trying to figure out some plugin to help server a service worker. So before I get my hands too dirty, I thought I'd be cheeky and see if we are looking weeks or months here?

Awesome, sorry I didn't see it.

I'm having trouble getting this to work... and I feel like it has something to do with the fact that I'm setting --base-href=/SubDirectory/ when I build. Any reason why the service worker wouldn't work when this argument is set?

Maybe this will help: Feature: Route redirection to index.html.
@alexjlockwood

@osnoser1 Thanks for the tip! Are you suggesting I manually update the ngsw-manifest.json file after I build?

For now yes. 馃槂

@alexjlockwood, create a ngsw-manifest.json file with only the routing config specified in your project root. The generated manifest with file hashes will be merged into it at build time.

@alxhub Sorry for being a complete noob here, but do you mean like this?

{
  "routing": {
    "index": "/index.html",
    "routes": {
      "/": {
        "prefix": false
      },
      "/ShapeShifter": {
        "prefix": true
      }
    }
  }
}

My web app is here... I'm building it using ng build --prod --base-href=/ShapeShifter/ so that it serves at https://alexjlockwood.github.io/ShapeShifter. Not exactly sure what the desired ngsw-manifest.json end result is supposed to look like though.

@alxhub Friendly ping. :)

The problem I seem to be having is that the browser is still trying to retrieve the ngsw-manifest.json file from https://alexjlockwood.github.io/ngsw-manifest.json when it is actually located at https://alexjlockwood.github.io/ShapeShifter/ngsw-manifest.json. Is this something that can be changed via the routing config above?

@alxhub

I think that --base-href=/SubDirectory/ should be concated to the ngsw-manifest.json at routing.index.

Resulting in /SubDirectory/index.html to the sw.

Just a quick follow up... I ended up filing #5186 and once that got fixed everything seemed to work fine for me.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings