mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
injectServiceWorker plugin should accept callback
This commit is contained in:
parent
7952a34d64
commit
683ffa9ed3
@ -8,7 +8,7 @@ function contentHash(str) {
|
|||||||
return hasher.digest();
|
return hasher.digest();
|
||||||
}
|
}
|
||||||
|
|
||||||
function injectServiceWorker(swFile, otherUnhashedFiles, placeholdersPerChunk) {
|
function injectServiceWorker(swFile, findUnhashedFileNamesFromBundle, placeholdersPerChunk) {
|
||||||
const swName = path.basename(swFile);
|
const swName = path.basename(swFile);
|
||||||
let root;
|
let root;
|
||||||
let version;
|
let version;
|
||||||
@ -31,6 +31,7 @@ function injectServiceWorker(swFile, otherUnhashedFiles, placeholdersPerChunk) {
|
|||||||
logger = config.logger;
|
logger = config.logger;
|
||||||
},
|
},
|
||||||
generateBundle: async function(options, bundle) {
|
generateBundle: async function(options, bundle) {
|
||||||
|
const otherUnhashedFiles = findUnhashedFileNamesFromBundle(bundle);
|
||||||
const unhashedFilenames = [swName].concat(otherUnhashedFiles);
|
const unhashedFilenames = [swName].concat(otherUnhashedFiles);
|
||||||
const unhashedFileContentMap = unhashedFilenames.reduce((map, fileName) => {
|
const unhashedFileContentMap = unhashedFilenames.reduce((map, fileName) => {
|
||||||
const chunkOrAsset = bundle[fileName];
|
const chunkOrAsset = bundle[fileName];
|
||||||
|
@ -37,7 +37,7 @@ export default defineConfig(({mode}) => {
|
|||||||
// important this comes before service worker
|
// important this comes before service worker
|
||||||
// otherwise the manifest and the icons it refers to won't be cached
|
// otherwise the manifest and the icons it refers to won't be cached
|
||||||
injectWebManifest("assets/manifest.json"),
|
injectWebManifest("assets/manifest.json"),
|
||||||
injectServiceWorker("./src/platform/web/sw.js", ["index.html", "assets/config.json", "assets/theme-element.json"], {
|
injectServiceWorker("./src/platform/web/sw.js", findUnhashedFileNamesFromBundle, {
|
||||||
// placeholders to replace at end of build by chunk name
|
// placeholders to replace at end of build by chunk name
|
||||||
index: {
|
index: {
|
||||||
DEFINE_GLOBAL_HASH: definePlaceholders.DEFINE_GLOBAL_HASH,
|
DEFINE_GLOBAL_HASH: definePlaceholders.DEFINE_GLOBAL_HASH,
|
||||||
@ -48,3 +48,16 @@ export default defineConfig(({mode}) => {
|
|||||||
define: definePlaceholders,
|
define: definePlaceholders,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function findUnhashedFileNamesFromBundle(bundle) {
|
||||||
|
const names = ["index.html"];
|
||||||
|
for (const fileName of Object.keys(bundle)) {
|
||||||
|
if (fileName.includes("config.json")) {
|
||||||
|
names.push(fileName);
|
||||||
|
}
|
||||||
|
if (/theme-.+\.json/.test(fileName)) {
|
||||||
|
names.push(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user