Last active
November 1, 2017 14:19
-
-
Save whmountains/f477620b1336c51d6ab8150207466d13 to your computer and use it in GitHub Desktop.
Create AppCache based on parameters from sw-precache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SW_PRECACHE_CONFIG = './sw-precache-config' | |
const OUT_FILE = 'build/precache.appcache' | |
const glob = require('globby') | |
const { staticFileGlobs, stripPrefix } = require(SW_PRECACHE_CONFIG) | |
const fs = require('fs') | |
const path = require('path') | |
glob(staticFileGlobs).then(files => { | |
// filter out directories | |
files = files.filter(file => fs.statSync(file).isFile()) | |
// strip out prefix | |
files = files.map(file => file.replace(stripPrefix, '')) | |
// add the header and join to string | |
const out = ['CACHE MANIFEST', ...files].join('\n') | |
// write the file | |
fs.writeFileSync(path.join(__dirname, OUT_FILE), out) | |
// we're done! | |
console.log(`Wrote ${OUT_FILE} with ${files.length} resources.`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment