Skip to content

Commit

Permalink
More caution
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-matt-hillsdon committed May 29, 2024
1 parent 589b815 commit 2b1cc97
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const theme = "@microbit-foundation/python-editor-v3-microbit";
const external = `node_modules/${theme}`;
const internal = "src/deployment/default";

const featurePwa = process.env.FEATURE_PWA === "true";

// There are third-party options but seems better to just depend on ejs.
const viteEjsPlugin = ({ data }: { data: ejs.Data }): Plugin => ({
name: "ejs",
Expand All @@ -30,7 +32,8 @@ const viteEjsPlugin = ({ data }: { data: ejs.Data }): Plugin => ({
});

// Removes webmanifest link tag from output index.html file.
// We add this tag if PWA features are enabled via a feature flag.
// We readd this client side if PWA features are enabled via a feature flag.
// When that feature flag goes this plugin can be removed.
const viteRemoveManifestPlugin = (): Plugin => ({
name: "Manifest",
enforce: "post",
Expand All @@ -40,12 +43,16 @@ const viteRemoveManifestPlugin = (): Plugin => ({
html: string,
_ctx: IndexHtmlTransformContext
): IndexHtmlTransformResult => {
return html.replace(
const updated = html.replace(
`<link rel="manifest" href="${
process.env.BASE_URL ?? "/"
}manifest.webmanifest">`,
""
);
if (featurePwa && updated == html) {
throw new Error("Failed to remove web manifest");
}
return updated;
},
},
});
Expand Down Expand Up @@ -76,7 +83,7 @@ export default defineConfig(({ mode }) => {
react(),
svgr(),
VitePWA({
disable: process.env.FEATURE_PWA === "true",
disable: !featurePwa,
registerType: "autoUpdate",
workbox: {
cacheId:
Expand Down

0 comments on commit 2b1cc97

Please sign in to comment.