forked from mystiq/hydrogen-web
also look in chunks for cacheable assets for service worker
This commit is contained in:
parent
91e69a2bd0
commit
0e2a22f509
1 changed files with 4 additions and 6 deletions
|
@ -22,19 +22,17 @@ module.exports = function injectServiceWorker(swFile) {
|
||||||
},
|
},
|
||||||
generateBundle: async function(_, bundle) {
|
generateBundle: async function(_, bundle) {
|
||||||
const absoluteSwFile = path.resolve(root, swFile);
|
const absoluteSwFile = path.resolve(root, swFile);
|
||||||
const packageManifest = path.resolve(path.join(__dirname, "../../package.json"));
|
|
||||||
let swSource = await fs.readFile(absoluteSwFile, {encoding: "utf8"});
|
let swSource = await fs.readFile(absoluteSwFile, {encoding: "utf8"});
|
||||||
const assets = Object.values(bundle).filter(a => a.type === "asset");
|
const index = bundle["index.html"];
|
||||||
const cachedFileNames = assets.map(o => o.fileName).filter(fileName => fileName !== "index.html");
|
|
||||||
const r = Object.entries(bundle).find(([key, asset]) => key.includes("index.html"));
|
|
||||||
const index = assets.find(o => o.fileName === "index.html");
|
|
||||||
if (!index) {
|
if (!index) {
|
||||||
console.log("index not found", index, r);
|
console.log("index not found", index);
|
||||||
}
|
}
|
||||||
const uncachedFileContentMap = {
|
const uncachedFileContentMap = {
|
||||||
"index.html": index.source,
|
"index.html": index.source,
|
||||||
"sw.js": swSource
|
"sw.js": swSource
|
||||||
};
|
};
|
||||||
|
const assets = Object.values(bundle);
|
||||||
|
const cachedFileNames = assets.map(o => o.fileName).filter(fileName => fileName !== "index.html");
|
||||||
const globalHash = getBuildHash(cachedFileNames, uncachedFileContentMap);
|
const globalHash = getBuildHash(cachedFileNames, uncachedFileContentMap);
|
||||||
swSource = await buildServiceWorker(swSource, version, globalHash, assets);
|
swSource = await buildServiceWorker(swSource, version, globalHash, assets);
|
||||||
const outputName = path.basename(absoluteSwFile);
|
const outputName = path.basename(absoluteSwFile);
|
||||||
|
|
Loading…
Reference in a new issue