Skip to content

Instantly share code, notes, and snippets.

@cnp96
Last active April 15, 2020 23:29
Show Gist options
  • Save cnp96/aaba58ae5e400c25ad586f51f7bf3ca8 to your computer and use it in GitHub Desktop.
Save cnp96/aaba58ae5e400c25ad586f51f7bf3ca8 to your computer and use it in GitHub Desktop.
src/sw-build.js
const workboxBuild = require("workbox-build");
const buildSW = () => {
// The build is expected to fail if the
// sw install rules couldn't be generated.
// Add a catch block to handle this scenario.
return workboxBuild
.injectManifest({
swSrc: "src/sw-custom.js", // custom sw rule
swDest: "build/sw.js", // sw output file (auto-generated
globDirectory: "build",
globPatterns: ["**/*.{js,css,html,png,svg}"],
maximumFileSizeToCacheInBytes: 5 * 1024 * 102,
})
.then(({ count, size, warnings }) => {
warnings.forEach(console.warn);
console.info(`${count} files will be precached,
totaling ${size / (1024 * 1024)} MBs.`);
});
};
buildSW();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment