diff --git a/package.json b/package.json index e7e4340..3282ef0 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "module", "description": "Browser extension for subscribing to standard.site publications on the AT Protocol", "scripts": { - "build": "vite build && vite build --config vite.content.config.ts", + "build": "vite build", "check": "tsc --noEmit" }, "dependencies": { diff --git a/vite.config.ts b/vite.config.ts index f4e48c6..0e6566d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,23 +1,46 @@ import { defineConfig } from 'vite' import { resolve } from 'node:path' -// Builds the popup page and the background service worker. The content script -// needs its own IIFE build; see vite.content.config.ts. `npm run build` runs both. +// One build, two environments (Vite 6 builder API — `vite build` builds both +// in order): +// +// - `client`: the popup/auth pages and the background service worker, as ES +// modules. Empties dist/ and copies public/ (manifest, icons). +// - `content`: the content script as a single IIFE file, because MV3 content +// scripts cannot be ES modules. Builds second, into the same dist/. +// +// scripts/dev.mjs runs the same two environments in watch mode. export default defineConfig({ - build: { - outDir: 'dist', - emptyOutDir: true, - modulePreload: false, - rollupOptions: { - input: { - popup: resolve(__dirname, 'popup.html'), - auth: resolve(__dirname, 'auth.html'), - background: resolve(__dirname, 'src/background.ts'), + builder: {}, + environments: { + client: { + build: { + modulePreload: false, + rollupOptions: { + input: { + popup: resolve(__dirname, 'popup.html'), + auth: resolve(__dirname, 'auth.html'), + background: resolve(__dirname, 'src/background.ts'), + }, + output: { + entryFileNames: '[name].js', + chunkFileNames: 'chunks/[name]-[hash].js', + assetFileNames: 'assets/[name][extname]', + }, + }, }, - output: { - entryFileNames: '[name].js', - chunkFileNames: 'chunks/[name]-[hash].js', - assetFileNames: 'assets/[name][extname]', + }, + content: { + consumer: 'client', + build: { + emptyOutDir: false, // shares dist/ with the client environment + copyPublicDir: false, + lib: { + entry: resolve(__dirname, 'src/content.ts'), + name: 'substandardContent', + formats: ['iife'], + fileName: () => 'content.js', + }, }, }, }, diff --git a/vite.content.config.ts b/vite.content.config.ts deleted file mode 100644 index c87e220..0000000 --- a/vite.content.config.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { defineConfig } from 'vite' -import { resolve } from 'node:path' - -// Content scripts cannot be ES modules, so build content.ts separately as an IIFE. -export default defineConfig({ - build: { - outDir: 'dist', - emptyOutDir: false, - copyPublicDir: false, - lib: { - entry: resolve(__dirname, 'src/content.ts'), - name: 'substandardContent', - formats: ['iife'], - fileName: () => 'content.js', - }, - }, -})