From 8a3b695efb0c5897cfaa400bd3d95cd8fc72e1d3 Mon Sep 17 00:00:00 2001 From: do0ori Date: Sat, 19 Sep 2026 15:01:42 +0900 Subject: [PATCH] fix: Strip the service worker source map before deploy vite-plugin-pwa builds the service worker in a pass of its own, after every plugin hook the Sentry plugin's cleanup runs in, so service-worker.js.map survived and was published to GitHub Pages. Move the cleanup to a post-build step, which runs once the whole build including that pass is done. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01MUBfrDZLkPRPZQJxJWzeU4 --- package.json | 2 +- scripts/strip-sourcemaps.mjs | 17 +++++++++++++++++ vite.config.ts | 4 ++-- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 scripts/strip-sourcemaps.mjs diff --git a/package.json b/package.json index 1bdcd52..5b43f72 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "homepage": "https://do0ori.github.io/visual-timer", "scripts": { "dev": "vite", - "build": "tsc && vite build", + "build": "tsc && vite build && node scripts/strip-sourcemaps.mjs", "test": "jest --runInBand", "preview": "vite preview", "format": "prettier . --write" diff --git a/scripts/strip-sourcemaps.mjs b/scripts/strip-sourcemaps.mjs new file mode 100644 index 0000000..789981d --- /dev/null +++ b/scripts/strip-sourcemaps.mjs @@ -0,0 +1,17 @@ +// Runs after `vite build`, which builds the app and then — in vite-plugin-pwa's +// own pass, past every plugin hook — the service worker. Source maps only exist +// so the Sentry plugin can upload them during that build; none may be published +// to GitHub Pages, so drop whatever is left. +import { readdirSync, rmSync } from 'node:fs'; +import { join } from 'node:path'; + +const DIST = 'dist'; + +const removed = readdirSync(DIST, { recursive: true, encoding: 'utf-8' }) + .filter((entry) => entry.endsWith('.map')) + .map((entry) => { + rmSync(join(DIST, entry)); + return entry; + }); + +console.log(removed.length ? `Stripped source maps: ${removed.join(', ')}` : 'No source maps to strip.'); diff --git a/vite.config.ts b/vite.config.ts index 9e40faa..afb4e3f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -68,8 +68,8 @@ export default defineConfig({ }), ], build: { - // Generated only when they can be uploaded to Sentry, and deleted from dist - // afterwards, so source maps are never published to GitHub Pages. + // Generated only when they can be uploaded to Sentry. `strip-sourcemaps` + // clears the leftovers afterwards, so none are published to GitHub Pages. sourcemap: uploadSourcemaps ? 'hidden' : false, }, server: {