Skip to content

Commit

Permalink
Handle base URL and webmanifest link tag with feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-robert committed Apr 29, 2024
1 parent 5233dff commit 5877fc6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
15 changes: 0 additions & 15 deletions public/manifest.webmanifest

This file was deleted.

45 changes: 41 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ 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.
const viteRemoveManifestPlugin = (): Plugin => ({
name: "Manifest",
enforce: "post",
transformIndexHtml: {
order: "post",
handler: (
html: string,
_ctx: IndexHtmlTransformContext
): IndexHtmlTransformResult => {
return html.replace(
`<link rel="manifest" href="${
process.env.BASE_URL ?? "/"
}manifest.webmanifest">`,
""
);
},
},
});

export default defineConfig(({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
const unitTest: UserConfig["test"] = {
Expand Down Expand Up @@ -126,11 +147,27 @@ export default defineConfig(({ mode }) => {
},
],
},
// See manifest.webmanifest in public/
// It has been split out so we can inject it if enabled
// via feature flag.
manifest: false,
manifest: {
name: "micro:bit Python Editor",
short_name: "micro:bit Python Editor",
description:
"A Python Editor for the BBC micro:bit, built by the Micro:bit Educational Foundation and the global Python Community.",
theme_color: "#6c4bc1",
icons: [
{
src: `${process.env.BASE_URL ?? "/"}logo512.png`,
sizes: "512x512",
type: "image/png",
},
{
src: `${process.env.BASE_URL ?? "/"}logo192.png`,
sizes: "192x192",
type: "image/png",
},
],
},
}),
viteRemoveManifestPlugin(),
],
test: unitTest,
resolve: {
Expand Down

0 comments on commit 5877fc6

Please sign in to comment.