-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(gatsby-plugin-offline): Allow appending custom scripts to sw.js #11626
feat(gatsby-plugin-offline): Allow appending custom scripts to sw.js #11626
Conversation
@pieh should be ready to merge now! |
|
||
if (pluginOptions.injectScript) { | ||
const userAppend = fs.readFileSync(pluginOptions.injectScript, `utf8`) | ||
fs.appendFileSync(`public/sw.js`, `\n` + userAppend) |
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.
What do you think of wrapping this in a try catch here and printing a friendly error if the file doesn't exist? Definitely not a blocker for this PR though.
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.
Agreed, I'll implement this change
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, just done this!
Left a few comments but overall looks great, @davidbailey00! 👍 |
I was just checking some docs - and was wondering if we could just document how to use |
@davidbailey00 if it's possible to use workbox's |
It was introduced in Workbox 4.3 |
So we can't use it since we're on v3 still. |
Would it be worth updating to workbox 4 instead of doing this? |
Hmm we could use the Workbox option - it wouldn't just be a one-stop operation though, since we would need to insert the content hash into the filename for any custom scripts this way and then modify the filenames in the config to match, so the first version is not cached forever. The approach taken in this PR instead inserts the custom code into the |
Maybe we could do this on user behalf if |
Moving this out of "In Progress" for now. We can circle back to it. |
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.
Looks good! Thank you so much for wrapping this up @davidbailey00 🥇
Co-Authored-By: Sidhartha Chatterjee <[email protected]>
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.
👍
Need to fix these
|
…/gatsby into offline-plugin-custom-code
|
Running this on org and posting a build url here in a bit |
Looks like this works great on https://gatsby-org-offline3-test.netlify.com/ |
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.
Thanks for working on this! 💃
Published in |
No description provided.