fix: assetCachePrefix undefined
This commit is contained in:
parent
050d5a7ac9
commit
6489efdd1a
1 changed files with 8 additions and 7 deletions
15
index.js
15
index.js
|
@ -4,6 +4,7 @@ import { randomUUID } from "node:crypto";
|
||||||
import path from 'pathe';
|
import path from 'pathe';
|
||||||
import { build } from 'esbuild';
|
import { build } from 'esbuild';
|
||||||
|
|
||||||
|
const ASTROSW = 'astro-sw';
|
||||||
/**
|
/**
|
||||||
* @typedef {import('astro').AstroIntegration} AstroIntegration
|
* @typedef {import('astro').AstroIntegration} AstroIntegration
|
||||||
* @typedef {import('esbuild').BuildOptions} BuildOptions
|
* @typedef {import('esbuild').BuildOptions} BuildOptions
|
||||||
|
@ -26,7 +27,7 @@ import { build } from 'esbuild';
|
||||||
*/
|
*/
|
||||||
export default function serviceWorker(config) {
|
export default function serviceWorker(config) {
|
||||||
let {
|
let {
|
||||||
assetCachePrefix,
|
assetCachePrefix = ASTROSW,
|
||||||
assetCacheVersionID = randomUUID(),
|
assetCacheVersionID = randomUUID(),
|
||||||
path: serviceWorkerPath,
|
path: serviceWorkerPath,
|
||||||
customRoutes = [],
|
customRoutes = [],
|
||||||
|
@ -48,21 +49,21 @@ export default function serviceWorker(config) {
|
||||||
});
|
});
|
||||||
if (registration.installing) {
|
if (registration.installing) {
|
||||||
// installingFn();
|
// installingFn();
|
||||||
console.log('[astro-sw] Installing...')
|
console.log('[${ASTROSW}] Installing...')
|
||||||
} else if (registration.waiting) {
|
} else if (registration.waiting) {
|
||||||
// installedFn();
|
// installedFn();
|
||||||
console.log('[astro-sw] Installed...')
|
console.log('[${ASTROSW}] Installed...')
|
||||||
} else if (registration.active) {
|
} else if (registration.active) {
|
||||||
// activeFn();
|
// activeFn();
|
||||||
console.log('[astro-sw] Active...')
|
console.log('[${ASTROSW}] Active...')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// onError(error);
|
// onError(error);
|
||||||
console.error('[astro-sw] ERR', error)
|
console.error('[${ASTROSW}] ERR', error)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// onUnsupported();
|
// onUnsupported();
|
||||||
console.log('[astro-sw] Browser does not support Service Worker')
|
console.log('[${ASTROSW}] Browser does not support Service Worker')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ export default function serviceWorker(config) {
|
||||||
const __dirname = path.resolve(path.dirname('.'));
|
const __dirname = path.resolve(path.dirname('.'));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'name': 'astro-sw',
|
'name': ASTROSW,
|
||||||
'hooks': {
|
'hooks': {
|
||||||
'astro:config:setup': async ({ injectScript, config, command, logger }) => {
|
'astro:config:setup': async ({ injectScript, config, command, logger }) => {
|
||||||
output = config.output;
|
output = config.output;
|
||||||
|
|
Loading…
Reference in a new issue