diff --git a/packages/gatsby-plugin-offline/.gitignore b/packages/gatsby-plugin-offline/.gitignore index 8c9686624a187..10cf84f0d2dc8 100644 --- a/packages/gatsby-plugin-offline/.gitignore +++ b/packages/gatsby-plugin-offline/.gitignore @@ -1,3 +1,4 @@ /*.js !index.js +!sw-append.js yarn.lock diff --git a/packages/gatsby-plugin-offline/README.md b/packages/gatsby-plugin-offline/README.md index 01ebf254e5d91..073aa58715007 100644 --- a/packages/gatsby-plugin-offline/README.md +++ b/packages/gatsby-plugin-offline/README.md @@ -40,12 +40,12 @@ const options = { cacheId: `gatsby-plugin-offline`, // Don't cache-bust JS or CSS files, and anything in the static directory, // since these files have unique URLs and their contents will never change - dontCacheBustUrlsMatching: /(\.js$|\.css$|\/static\/)/, + dontCacheBustUrlsMatching: /(\.js$|\.css$|static\/)/, runtimeCaching: [ { // Use cacheFirst since these don't need to be revalidated (same RegExp // and same reason as above) - urlPattern: /(\.js$|\.css$|\/static\/)/, + urlPattern: /(\.js$|\.css$|static\/)/, handler: `cacheFirst`, }, { diff --git a/packages/gatsby-plugin-offline/src/gatsby-node.js b/packages/gatsby-plugin-offline/src/gatsby-node.js index c522b426b51f1..4d014c439ed8a 100644 --- a/packages/gatsby-plugin-offline/src/gatsby-node.js +++ b/packages/gatsby-plugin-offline/src/gatsby-node.js @@ -82,12 +82,12 @@ exports.onPostBuild = (args, pluginOptions) => { cacheId: `gatsby-plugin-offline`, // Don't cache-bust JS or CSS files, and anything in the static directory, // since these files have unique URLs and their contents will never change - dontCacheBustUrlsMatching: /(\.js$|\.css$|\/static\/)/, + dontCacheBustUrlsMatching: /(\.js$|\.css$|static\/)/, runtimeCaching: [ { // Use cacheFirst since these don't need to be revalidated (same RegExp // and same reason as above) - urlPattern: /(\.js$|\.css$|\/static\/)/, + urlPattern: /(\.js$|\.css$|static\/)/, handler: `cacheFirst`, }, { @@ -126,7 +126,7 @@ exports.onPostBuild = (args, pluginOptions) => { .readFileSync(`${__dirname}/sw-append.js`, `utf8`) .replace(/%pathPrefix%/g, pathPrefix) - fs.appendFileSync(`public/sw.js`, swAppend) + fs.appendFileSync(`public/sw.js`, `\n` + swAppend) console.log( `Generated ${swDest}, which will precache ${count} files, totaling ${size} bytes.` ) diff --git a/packages/gatsby-plugin-offline/src/sw-append.js b/packages/gatsby-plugin-offline/sw-append.js similarity index 100% rename from packages/gatsby-plugin-offline/src/sw-append.js rename to packages/gatsby-plugin-offline/sw-append.js