Skip to content

Commit

Permalink
Merge branch 'pwa' into mod-pwa
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-matt-hillsdon committed May 29, 2024
2 parents 357d9fa + 7bc9cf5 commit f6d1673
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ const external = `node_modules/${theme}`;
const internal = "src/deployment/default";

const featurePwa = process.env.FEATURE_PWA === "true";
const pwaCacheId =
// v3 vs beta should have distinct caches
// for the moment we do this for all review stages too but likely that's too much over time
process.env.STAGE === "PRODUCTION" ||
process.env.STAGE === "STAGING" ||
process.env.STAGE === "REVIEW"
? process.env.BASE_URL.replaceAll("/", "") + "-"
: undefined;

// There are third-party options but seems better to just depend on ejs.
const viteEjsPlugin = ({ data }: { data: ejs.Data }): Plugin => ({
Expand Down Expand Up @@ -86,14 +94,7 @@ export default defineConfig(({ mode }) => {
disable: !featurePwa,
registerType: "autoUpdate",
workbox: {
cacheId:
// v3 vs beta should have distinct caches
// for the moment we do this for all review stages too but likely that's too much over time
process.env.STAGE === "PRODUCTION" ||
process.env.STAGE === "STAGING" ||
process.env.STAGE === "REVIEW"
? process.env.BASE_URL.replaceAll("/", "") + "-"
: undefined,
cacheId: pwaCacheId,
// Only precache language assets for the fallback language.
// Cache other languages at runtime.
globIgnores: [
Expand All @@ -108,7 +109,7 @@ export default defineConfig(({ mode }) => {
),
handler: "NetworkFirst",
options: {
cacheName: "sanity-content-cache",
cacheName: `${pwaCacheId}-sanity-content-cache`,
expiration: {
maxEntries: 40,
},
Expand All @@ -123,7 +124,7 @@ export default defineConfig(({ mode }) => {
),
handler: "CacheFirst",
options: {
cacheName: "sanity-images-cache",
cacheName: `${pwaCacheId}-sanity-images-cache`,
expiration: {
maxEntries: 100,
},
Expand All @@ -136,7 +137,7 @@ export default defineConfig(({ mode }) => {
urlPattern: /^https:\/\/fonts.microbit.org\/.*/,
handler: "CacheFirst",
options: {
cacheName: "fonts-cache",
cacheName: `${pwaCacheId}-fonts-cache`,
expiration: {
maxEntries: 10,
},
Expand All @@ -150,7 +151,7 @@ export default defineConfig(({ mode }) => {
/.*(?:pyright-locale|search\.worker|typeshed|ui\.).*\.js/,
handler: "CacheFirst",
options: {
cacheName: "lang-cache",
cacheName: `${pwaCacheId}-lang-cache`,
expiration: {
maxEntries: 40,
},
Expand Down

0 comments on commit f6d1673

Please sign in to comment.