From d3be31d669702ca283dae568e3b9200e64887851 Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Tue, 13 May 2025 13:31:42 +0200 Subject: [PATCH] feat(pwa): new service worker declaration with custom route --- routes/sw.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 routes/sw.ts diff --git a/routes/sw.ts b/routes/sw.ts new file mode 100644 index 0000000..1ea0f18 --- /dev/null +++ b/routes/sw.ts @@ -0,0 +1,19 @@ +import { define } from '../utils.ts' +import { bundle } from '@deno/emit' +import config from '../deno.json' with { type: 'json' } + +export const handler = define.handlers(async (ctx) => { + const { code } = await bundle('./src/serviceworker/mod.ts', { + minify: true, + importMap: { imports: config.imports }, + compilerOptions: { + inlineSourceMap: ctx.config.mode === 'development', + }, + }) + + return new Response(code, { + headers: { + 'Content-Type': 'text/javascript', + }, + }) +})