From e8dff6d16b80c0b01b1c09ebc3e17477e8894da9 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 17 Aug 2021 14:13:27 -0700 Subject: [PATCH] Move web-specific files to platform/web --- scripts/build.mjs | 12 ++++++------ snowpack.config.js | 4 ++-- {public => src/platform/web/docroot}/index.html | 2 +- src/platform/web/{ => docroot}/service-worker.js | 0 sw.js | 1 - 5 files changed, 9 insertions(+), 10 deletions(-) rename {public => src/platform/web/docroot}/index.html (97%) rename src/platform/web/{ => docroot}/service-worker.js (100%) delete mode 120000 sw.js diff --git a/scripts/build.mjs b/scripts/build.mjs index e97e5a1c..fd5183de 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -72,7 +72,7 @@ async function build({modernOnly, overrideImports, overrideCss}) { if (overrideImports) { importOverridesMap = await readImportOverrides(overrideImports); } - const devHtml = await fs.readFile(path.join(projectDir, "public/index.html"), "utf8"); + const devHtml = await fs.readFile(path.join(snowpackOutPath, "index.html"), "utf8"); const doc = cheerio.load(devHtml); const themes = []; findThemes(doc, themeName => { @@ -105,9 +105,9 @@ async function build({modernOnly, overrideImports, overrideCss}) { await buildCssBundles(buildCssLegacy, themes, assets, overrideCss); await buildManifest(assets); // all assets have been added, create a hash from all assets name to cache unhashed files like index.html - assets.addToHashForAll("public/index.html", devHtml); - let swSource = await fs.readFile(path.join(projectDir, srcPath("platform/web/service-worker.js")), "utf8"); - assets.addToHashForAll("sw.js", swSource); + assets.addToHashForAll("index.html", devHtml); + let swSource = await fs.readFile(path.join(snowpackOutPath, "service-worker.js"), "utf8"); + assets.addToHashForAll("service-worker.js", swSource); const globalHash = assets.hashForAll(); @@ -166,7 +166,7 @@ async function buildHtml(doc, version, baseConfig, globalHash, modernOnly, asset const configJSON = JSON.stringify(Object.assign({}, baseConfig, { worker: assets.has("worker.js") ? assets.resolve(`worker.js`) : null, downloadSandbox: assets.resolve("download-sandbox.html"), - serviceWorker: "sw.js", + serviceWorker: "service-worker.js", olm: { wasm: assets.resolve("olm.wasm"), legacyBundle: assets.resolve("olm_legacy.js"), @@ -334,7 +334,7 @@ async function buildServiceWorker(swSource, version, globalHash, assets) { swSource = replaceStringInSource("NOTIFICATION_BADGE_ICON", assets.resolve("icon.png")); // service worker should not have a hashed name as it is polled by the browser for updates - await assets.writeUnhashed("sw.js", swSource); + await assets.writeUnhashed("service-worker.js", swSource); } async function buildCssBundles(buildFn, themes, assets, mainCssFile = null) { diff --git a/snowpack.config.js b/snowpack.config.js index 5cc4222b..3de1d723 100644 --- a/snowpack.config.js +++ b/snowpack.config.js @@ -4,10 +4,10 @@ /** @type {import("snowpack").SnowpackUserConfig } */ module.exports = { mount: { + // More specific paths before less specific paths (if they overlap) + "src/platform/web/docroot": "/", "src": "/src", - "public": "/", "lib": {url: "/lib", static: true }, - "src/platform/web/ui/css/themes": "/themes", "assets": "/assets", /* ... */ }, diff --git a/public/index.html b/src/platform/web/docroot/index.html similarity index 97% rename from public/index.html rename to src/platform/web/docroot/index.html index 0b266ff3..90af082a 100644 --- a/public/index.html +++ b/src/platform/web/docroot/index.html @@ -26,7 +26,7 @@ downloadSandbox: "assets/download-sandbox.html", defaultHomeServer: "matrix.org", // NOTE: uncomment this if you want the service worker for local development - // serviceWorker: "sw.js", + // serviceWorker: "service-worker.js", // NOTE: provide push config if you want push notifs for local development // see assets/config.json for what the config looks like // push: {...}, diff --git a/src/platform/web/service-worker.js b/src/platform/web/docroot/service-worker.js similarity index 100% rename from src/platform/web/service-worker.js rename to src/platform/web/docroot/service-worker.js diff --git a/sw.js b/sw.js deleted file mode 120000 index edcb3642..00000000 --- a/sw.js +++ /dev/null @@ -1 +0,0 @@ -src/platform/web/service-worker.js \ No newline at end of file