Conversation
May I, at this point, say thank you for implementing this? Cheers 🎉 👍 |
I'd love for this to get merged in so I can deprecate https://github.com/markdalgleish/serviceworker-loader. |
This PR is pretty straight forward, but I think the more important part is #15. I don't know what useful things people would do with a service worker that don't include the list of assets from webpack that need to be cached. #15 introduces a magic #15 functions, but really needs some help before it's ready to merge. Any help would be greatly appreciated. |
@markdalgleish Are you able to help get both of my PRs merged? #15 still needs some help. I've had these PRs open for 3 months now and you're the only webpack member I've seen a response from. |
this loader works well for me so far. love it. thx @AsaAyers |
constructor = "require(" + JSON.stringify("!!" + path.join(__dirname, "createInlineWorker.js")) + ")(" + | ||
var constructor | ||
if(query.service) { | ||
constructor = "navigator.serviceWorker.register(__webpack_public_path__ + " + JSON.stringify(workerFile) + ", options);" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add detection here? Worker is pretty much defined everywhere, serviceWorker isn't
maybe something like
navigator.serviceWorker ? navigator.serviceWorker.register(__webpack_public_path__ + " + JSON.stringify(workerFile) + ", options) : Promise.reject('No support')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, now it rejects if navigator.serviceWorker
is missing.
@markdalgleish I see you're a webpack member now. Are you able to help with this and #15? |
Is there some example to use this with SW? I don't think the way below is correct. myServiceWorker = require('worker!./sw.js')
navigator.serviceWorker.register(myServiceWorker) Edit: I thought it's already merged so I was finding it's usage in master branch. Sorry for confusing you! |
If you want a regular worker the code is: myServiceWorker = require('worker!./sw.js')
new myServiceWorker() On my branch you create a service worker using: myServiceWorker = require('worker?service!./sw.js')
new myServiceWorker() |
var constructor | ||
if(query.service) { | ||
constructor = "('serviceWorker' in navigator)" + | ||
"? navigator.serviceWorker.register(__webpack_public_path__ + " + JSON.stringify(workerFile) + ", options);" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting a syntax error in the generated code on this line, caused by the semi-colon before the ternary operator colon:
If you remove it, it seems to work correctly.
? navigator.serviceWorker.register(__webpack_public_path__ + " + JSON.stringify(workerFile) + ", options) "
ServiceWorkers
Duplicate of #32 ? |
I'm making https://github.com/pulls more useful to me today by closing my old PRs. |
Fixes #11