From 0c8d5edd77864c80e812d294c81ac879a69d0d30 Mon Sep 17 00:00:00 2001 From: ayoayco Date: Mon, 19 Aug 2024 13:53:19 +0200 Subject: [PATCH] feat: new experimental Strategies export --- astro.config.mjs | 4 ++++ packages/index.js | 8 ++++++++ packages/strategies/CacheRevalidatePreloadFallback.js | 2 +- packages/strategies/index.js | 5 +++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 packages/strategies/index.js diff --git a/astro.config.mjs b/astro.config.mjs index c030e97..f9cd856 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -3,6 +3,7 @@ import { defineConfig } from "astro/config"; import node from "@astrojs/node"; import serviceWorker from "./packages/index.js"; +import { Strategies } from "./packages/strategies/index.js"; export default defineConfig({ output: "hybrid", @@ -32,6 +33,9 @@ export default defineConfig({ const sw = await navigator.serviceWorker.getRegistration(); console.log('>>> registrered', sw) } + }, + experimental: { + strategy: Strategies.CacheRevalidatePreloadFallback, } }) ] diff --git a/packages/index.js b/packages/index.js index 8bd043b..79a6335 100644 --- a/packages/index.js +++ b/packages/index.js @@ -33,6 +33,14 @@ const ASTROSW = '@ayco/astro-sw'; * unsupported?: () => void, * afterRegistration?: () => void, * } + * experimental?: { + * strategy?: { + * fetchFn: () => void, + * installFn: () => void, + * activateFn: () => void, + * waitFn: () => void, + * } + * } * }} options * @returns {AstroIntegration} */ diff --git a/packages/strategies/CacheRevalidatePreloadFallback.js b/packages/strategies/CacheRevalidatePreloadFallback.js index 43e630f..8224319 100644 --- a/packages/strategies/CacheRevalidatePreloadFallback.js +++ b/packages/strategies/CacheRevalidatePreloadFallback.js @@ -142,7 +142,7 @@ const fetchFn = (event) => { const waitFn = (event) => {} -export default { +export const CacheRevalidatePreloadFallback = { fetchFn, installFn, activateFn, diff --git a/packages/strategies/index.js b/packages/strategies/index.js new file mode 100644 index 0000000..4a1ef97 --- /dev/null +++ b/packages/strategies/index.js @@ -0,0 +1,5 @@ +import { CacheRevalidatePreloadFallback } from "./CacheRevalidatePreloadFallback.js"; + +export const Strategies = { + CacheRevalidatePreloadFallback +} \ No newline at end of file