Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: consolidate vite SW+main builds via Environment API (#41047)
Simon Knottbc2960793c05
diff --git a/packages/extension/vite.config.mts b/packages/extension/vite.config.mtsindex 89ec56c689..01bc27c9c3 100644--- a/packages/extension/vite.config.mts+++ b/packages/extension/vite.config.mts@@ -19,7 +19,6 @@ import { defineConfig } from 'vite';import react from '@vitejs/plugin-react';import { viteStaticCopy } from 'vite-plugin-static-copy';-// https://vitejs.dev/config/export default defineConfig({plugins: [react(),@@ -37,17 +36,35 @@ export default defineConfig({})],root: resolve(__dirname, 'src/ui'),- build: {- outDir: resolve(__dirname, 'dist/'),- emptyOutDir: false,- minify: false,- rollupOptions: {- input: ['src/ui/connect.html', 'src/ui/status.html'],- output: {- manualChunks: undefined,- entryFileNames: 'lib/ui/[name].js',- chunkFileNames: 'lib/ui/[name].js',- assetFileNames: 'lib/ui/[name].[ext]'+ builder: {},+ environments: {+ client: {+ build: {+ outDir: resolve(__dirname, 'dist/'),+ emptyOutDir: false,+ minify: false,+ rollupOptions: {+ input: ['src/ui/connect.html', 'src/ui/status.html'],+ output: {+ manualChunks: undefined,+ entryFileNames: 'lib/ui/[name].js',+ chunkFileNames: 'lib/ui/[name].js',+ assetFileNames: 'lib/ui/[name].[ext]'+ }+ }+ }+ },+ sw: {+ consumer: 'client',+ build: {+ outDir: resolve(__dirname, 'dist/'),+ emptyOutDir: false,+ minify: false,+ lib: {+ entry: resolve(__dirname, 'src/background.ts'),+ fileName: 'lib/background',+ formats: ['es']+ }}}}diff --git a/packages/extension/vite.sw.config.mts b/packages/extension/vite.sw.config.mtsdeleted file mode 100644index a383e4b4a5..0000000000--- a/packages/extension/vite.sw.config.mts+++ /dev/null@@ -1,31 +0,0 @@-/**- * Copyright (c) Microsoft Corporation.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import { resolve } from 'path';-import { defineConfig } from 'vite';--export default defineConfig({- build: {- lib: {- entry: resolve(__dirname, 'src/background.ts'),- fileName: 'lib/background',- formats: ['es']- },- outDir: 'dist',- emptyOutDir: false,- minify: false- }-});diff --git a/packages/trace-viewer/vite.config.ts b/packages/trace-viewer/vite.config.tsindex f88f723d05..3d0f63e65e 100644--- a/packages/trace-viewer/vite.config.ts+++ b/packages/trace-viewer/vite.config.ts@@ -42,20 +42,42 @@ export default defineConfig({'@web': path.resolve(__dirname, '../web/src'),},},- build: {- outDir: path.resolve(__dirname, '../playwright-core/lib/vite/traceViewer'),- emptyOutDir: false,- rollupOptions: {- input: {- index: path.resolve(__dirname, 'index.html'),- uiMode: path.resolve(__dirname, 'uiMode.html'),- snapshot: path.resolve(__dirname, 'snapshot.html'),+ builder: {},+ environments: {+ client: {+ build: {+ outDir: path.resolve(__dirname, '../playwright-core/lib/vite/traceViewer'),+ emptyOutDir: false,+ rollupOptions: {+ input: {+ index: path.resolve(__dirname, 'index.html'),+ uiMode: path.resolve(__dirname, 'uiMode.html'),+ snapshot: path.resolve(__dirname, 'snapshot.html'),+ },+ output: {+ entryFileNames: () => '[name].[hash].js',+ assetFileNames: () => '[name].[hash][extname]',+ manualChunks: undefined,+ },+ },},- output: {- entryFileNames: () => '[name].[hash].js',- assetFileNames: () => '[name].[hash][extname]',- manualChunks: undefined,+ },+ sw: {+ consumer: 'client',+ build: {+ outDir: path.resolve(__dirname, '../playwright-core/lib/vite/traceViewer'),+ emptyOutDir: false,+ rollupOptions: {+ input: {+ sw: path.resolve(__dirname, 'src/sw-main.ts'),+ },+ output: {+ entryFileNames: () => 'sw.bundle.js',+ assetFileNames: () => 'sw.[hash][extname]',+ manualChunks: undefined,+ },+ },},},- }+ },});diff --git a/packages/trace-viewer/vite.sw.config.ts b/packages/trace-viewer/vite.sw.config.tsdeleted file mode 100644index 1c53ac27db..0000000000--- a/packages/trace-viewer/vite.sw.config.ts+++ /dev/null@@ -1,56 +0,0 @@-/**- * Copyright (c) Microsoft Corporation.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import path from 'path';--import { defineConfig } from 'vite';-import react from '@vitejs/plugin-react';--import { bundle } from './bundle';--// https://vitejs.dev/config/-export default defineConfig({- base: '',- plugins: [- react(),- bundle()- ],- resolve: {- alias: {- '@isomorphic': path.resolve(__dirname, '../isomorphic'),- '@protocol': path.resolve(__dirname, '../protocol/src'),- '@testIsomorphic': path.resolve(__dirname, '../playwright/src/isomorphic'),- '@trace': path.resolve(__dirname, '../trace/src'),- '@web': path.resolve(__dirname, '../web/src'),- },- },- publicDir: false,- build: {- outDir: path.resolve(__dirname, '../playwright-core/lib/vite/traceViewer'),- // Output dir is shared with vite.config.ts, clearing it here is racy.- emptyOutDir: false,- rollupOptions: {- input: {- sw: path.resolve(__dirname, 'src/sw-main.ts'),- },- output: {- entryFileNames: info => 'sw.bundle.js',- assetFileNames: () => 'sw.[hash][extname]',- manualChunks: undefined,- },- },- }-});diff --git a/utils/build/build.js b/utils/build/build.jsindex 964c2a620f..814da980b2 100644--- a/utils/build/build.js+++ b/utils/build/build.js@@ -857,29 +857,12 @@ const pkgSizePlugin = {},};-// Build/watch trace viewer service worker.-steps.push(new ProgramStep({- 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,-}));-// Build/watch web packages. The html-reporter, trace-viewer, and dashboard// also have embedded Vite dev servers used when viewing reports/traces/the// dashboard live, but their bundled output is consumed as a static artifact// in other code paths (e.g. HtmlBuilder.build() reads lib/vite/htmlReport/// and lib/vite/traceViewer/), so we always keep the static build alongside-// HMR. Recorder is not yet HMR'd. The trace viewer service worker still-// builds via vite.sw.config.ts above — that step is not in this loop.+// HMR. Recorder is not yet HMR'd.const webPackages = ['html-reporter', 'recorder', 'trace-viewer', 'dashboard'];for (const webPackage of webPackages) {steps.push(new ProgramStep({@@ -897,24 +880,20 @@ for (const webPackage of webPackages) {}));}-// Build/watch extension UI pages and service worker.-for (const config of ['vite.config.mts', 'vite.sw.config.mts']) {- steps.push(new ProgramStep({- command: 'npx',- args: [- 'vite',- 'build',- '--config',- config,- ...(watchMode ? ['--watch', '--minify=false'] : []),- ...(withSourceMaps ? ['--sourcemap=inline'] : []),- '--clearScreen=false',- ],- shell: true,- cwd: path.join(__dirname, '..', '..', 'packages', 'extension'),- concurrent: true,- }));-}+// Build/watch extension+steps.push(new ProgramStep({+ command: 'npx',+ args: [+ 'vite',+ 'build',+ ...(watchMode ? ['--watch', '--minify=false'] : []),+ ...(withSourceMaps ? ['--sourcemap=inline'] : []),+ '--clearScreen=false',+ ],+ shell: true,+ cwd: path.join(__dirname, '..', '..', 'packages', 'extension'),+ concurrent: true,+}));// Generate CLI help.onChanges.push({