Skip to content

Instantly share code, notes, and snippets.

@zevdg
Last active October 26, 2018 22:55
Show Gist options
  • Save zevdg/552530c973e01c9ff06ed14fb71465a8 to your computer and use it in GitHub Desktop.
Save zevdg/552530c973e01c9ff06ed14fb71465a8 to your computer and use it in GitHub Desktop.
// see https://github.com/GoogleChrome/workbox/issues/1384#issuecomment-433550967
function precacheManifestHack() {
console.log(
chalk.red(
"Applying dirty hack for https://github.com/GoogleChrome/workbox/issues/1384#issuecomment-433550967"
)
);
const globPath = path.join(
__dirname,
"/..",
"dist",
"precache-manifest.*.js"
);
glob(globPath, function(err, matches) {
if (err) {
throw err;
}
if (matches.length !== 1) {
throw new Error("matches.length for " + globPath + " !== 1");
}
const filepath = matches[0];
let self = {};
eval(fs.readFileSync(filepath, "utf8"));
let manifest = self.__precacheManifest;
let hash = manifest.filter(route => route.url === "/index.html")[0]
.revision;
manifest.push({ url: "/", revision: hash });
const outputStr = "self.__precacheManifest = " + JSON.stringify(manifest);
fs.writeFileSync(filepath, outputStr);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment