also content-hash the webapp manifest

This commit is contained in:
Bruno Windels 2020-08-14 11:06:39 +02:00
parent 0104e14e0b
commit 3c4805b267

View File

@ -78,10 +78,11 @@ async function build() {
const cssBundlePaths = await buildCssBundles(legacy ? buildCssLegacy : buildCss, themes, themeAssets); const cssBundlePaths = await buildCssBundles(legacy ? buildCssLegacy : buildCss, themes, themeAssets);
const assetPaths = createAssetPaths(jsBundlePath, cssBundlePaths, themeAssets); const assetPaths = createAssetPaths(jsBundlePath, cssBundlePaths, themeAssets);
let manifestPath;
if (offline) { if (offline) {
await buildOffline(version, assetPaths); manifestPath = await buildOffline(version, assetPaths);
} }
await buildHtml(doc, version, assetPaths); await buildHtml(doc, version, assetPaths, manifestPath);
console.log(`built ${PROJECT_ID}${legacy ? " legacy" : ""} ${version} successfully`); console.log(`built ${PROJECT_ID}${legacy ? " legacy" : ""} ${version} successfully`);
} }
@ -140,7 +141,7 @@ async function copyThemeAssets(themes, legacy) {
return assets; return assets;
} }
async function buildHtml(doc, version, assetPaths) { async function buildHtml(doc, version, assetPaths, manifestPath) {
// transform html file // transform html file
// change path to main.css to css bundle // change path to main.css to css bundle
doc("link[rel=stylesheet]:not([title])").attr("href", assetPaths.cssMainBundle()); doc("link[rel=stylesheet]:not([title])").attr("href", assetPaths.cssMainBundle());
@ -161,7 +162,7 @@ async function buildHtml(doc, version, assetPaths) {
if (offline) { if (offline) {
doc("html").attr("manifest", "manifest.appcache"); doc("html").attr("manifest", "manifest.appcache");
doc("head").append(`<link rel="manifest" href="manifest.json">`); doc("head").append(`<link rel="manifest" href="${manifestPath.substr(targetDir.length)}">`);
} }
await fs.writeFile(path.join(targetDir, "index.html"), doc.html(), "utf8"); await fs.writeFile(path.join(targetDir, "index.html"), doc.html(), "utf8");
} }
@ -245,11 +246,14 @@ async function buildOffline(version, assetPaths) {
start_url: "index.html", start_url: "index.html",
icons: [{"src": "icon-192.png", "sizes": "192x192", "type": "image/png"}], icons: [{"src": "icon-192.png", "sizes": "192x192", "type": "image/png"}],
}; };
await fs.writeFile(path.join(targetDir, "manifest.json"), JSON.stringify(webManifest), "utf8"); const manifestJson = JSON.stringify(webManifest);
const manifestPath = resource("manifest.json", manifestJson);
await fs.writeFile(manifestPath, manifestJson, "utf8");
// copy icon // copy icon
// should this icon have a content hash as well? // should this icon have a content hash as well?
let icon = await fs.readFile(path.join(projectDir, "icon.png")); let icon = await fs.readFile(path.join(projectDir, "icon.png"));
await fs.writeFile(path.join(targetDir, "icon-192.png"), icon); await fs.writeFile(path.join(targetDir, "icon-192.png"), icon);
return manifestPath;
} }
async function buildCssBundles(buildFn, themes, themeAssets) { async function buildCssBundles(buildFn, themes, themeAssets) {