chore: HMR for Trace Viewer build script changes (#33291)

This commit is contained in:
Simon Knott 2024-11-08 15:08:58 +01:00 committed by GitHub
parent 93b7b6e279
commit f7a388dcb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 19 deletions

View file

@ -22,3 +22,5 @@ dist-ssr
*.njsproj *.njsproj
*.sln *.sln
*.sw? *.sw?
public/sw.bundle.js

View file

@ -26,6 +26,9 @@ export default defineConfig({
react(), react(),
bundle() bundle()
], ],
define: {
'process.env': {},
},
resolve: { resolve: {
alias: { alias: {
'@injected': path.resolve(__dirname, '../playwright-core/src/server/injected'), '@injected': path.resolve(__dirname, '../playwright-core/src/server/injected'),
@ -38,8 +41,6 @@ export default defineConfig({
}, },
build: { build: {
outDir: path.resolve(__dirname, '../playwright-core/lib/vite/traceViewer'), outDir: path.resolve(__dirname, '../playwright-core/lib/vite/traceViewer'),
// Output dir is shared with vite.sw.config.ts, clearing it here is racy.
emptyOutDir: false,
rollupOptions: { rollupOptions: {
input: { input: {
index: path.resolve(__dirname, 'index.html'), index: path.resolve(__dirname, 'index.html'),

View file

@ -35,9 +35,10 @@ export default defineConfig({
'@web': path.resolve(__dirname, '../web/src'), '@web': path.resolve(__dirname, '../web/src'),
}, },
}, },
publicDir: false,
build: { build: {
outDir: path.resolve(__dirname, '../playwright-core/lib/vite/traceViewer'), // outputs into the public dir, where the build of vite.config.ts will pick it up
// Output dir is shared with vite.config.ts, clearing it here is racy. outDir: path.resolve(__dirname, 'public'),
emptyOutDir: false, emptyOutDir: false,
rollupOptions: { rollupOptions: {
input: { input: {

View file

@ -275,6 +275,22 @@ for (const bundle of bundles) {
}); });
} }
// Build/watch trace viewer service worker.
steps.push({
command: 'npx',
args: [
'vite',
'--config',
'vite.sw.config.ts',
'build',
...(watchMode ? ['--watch', '--minify=false'] : []),
...(withSourceMaps ? ['--sourcemap=inline'] : []),
],
shell: true,
cwd: path.join(__dirname, '..', '..', 'packages', 'trace-viewer'),
concurrent: watchMode, // feeds into trace-viewer's `public` directory, so it needs to be finished before trace-viewer build starts
});
// Build/watch web packages. // Build/watch web packages.
for (const webPackage of ['html-reporter', 'recorder', 'trace-viewer']) { for (const webPackage of ['html-reporter', 'recorder', 'trace-viewer']) {
steps.push({ steps.push({
@ -290,22 +306,17 @@ for (const webPackage of ['html-reporter', 'recorder', 'trace-viewer']) {
concurrent: true, concurrent: true,
}); });
} }
// Build/watch trace viewer service worker.
steps.push({
command: 'npx',
args: [
'vite',
'--config',
'vite.sw.config.ts',
'build',
...(watchMode ? ['--watch', '--minify=false'] : []),
...(withSourceMaps ? ['--sourcemap=inline'] : []),
],
shell: true,
cwd: path.join(__dirname, '..', '..', 'packages', 'trace-viewer'),
concurrent: true,
});
// web packages dev server
if (watchMode) {
steps.push({
command: 'npx',
args: ['vite', '--port', '44223', '--base', '/trace/'],
shell: true,
cwd: path.join(__dirname, '..', '..', 'packages', 'trace-viewer'),
concurrent: true,
});
}
// Generate injected. // Generate injected.
onChanges.push({ onChanges.push({