From 3fa33ca81f404f5a9bf44f1b83537a11678aafbd Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 18 Nov 2024 16:04:12 +0100 Subject: [PATCH] chore(build): fix bug where sw changes aren't copied in watch mode (#33579) --- utils/build/build.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/utils/build/build.js b/utils/build/build.js index a9c4f0336b..e988bcb4be 100644 --- a/utils/build/build.js +++ b/utils/build/build.js @@ -291,6 +291,25 @@ steps.push({ concurrent: watchMode, // feeds into trace-viewer's `public` directory, so it needs to be finished before trace-viewer build starts }); +if (watchMode) { + // the build above outputs into `packages/trace-viewer/public`, where the `vite build` for `packages/trace-viewer` is supposed to pick it up. + // there's a bug in `vite build --watch` though where the public dir is only copied over initially, but its not watched. + // to work around this, we run a second watch build of the service worker into the final output. + // bug: https://github.com/vitejs/vite/issues/18655 + steps.push({ + command: 'npx', + args: [ + 'vite', '--config', 'vite.sw.config.ts', + 'build', '--watch', '--minify=false', + '--outDir', path.join(__dirname, '..', '..', 'packages', 'playwright-core', 'lib', 'vite', 'trace-viewer'), + '--emptyOutDir=false' + ], + shell: true, + cwd: path.join(__dirname, '..', '..', 'packages', 'trace-viewer'), + concurrent: true + }); +} + // Build/watch web packages. for (const webPackage of ['html-reporter', 'recorder', 'trace-viewer']) { steps.push({