-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathvite.config.ts
More file actions
82 lines (80 loc) · 2.94 KB
/
vite.config.ts
File metadata and controls
82 lines (80 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { defineConfig } from 'vite';
import { crx } from '@crxjs/vite-plugin';
import manifest from './manifest.json' with { type: 'json' };
import pkg from './package.json' with { type: 'json' };
import path from 'path';
import { webmcpCompilerPlugin } from './scripts/vite-plugin-webmcp-compiler';
// Single source of truth: inject version from package.json into manifest
const manifestWithVersion = {
...manifest,
version: pkg.version,
};
export default defineConfig({
plugins: [
webmcpCompilerPlugin(), // Compile WebMCP tools first
crx({ manifest: manifestWithVersion }),
],
resolve: {
alias: [
{ find: '@', replacement: path.resolve(__dirname, './src') },
{ find: '@lib', replacement: path.resolve(__dirname, './src/lib') },
{ find: '@types', replacement: path.resolve(__dirname, './src/types') },
// Use CSP-safe Ajv shim - real Ajv uses new Function() which violates extension CSP
// Also fixes ESM import issue (ajv doesn't have default export in ESM)
// Regex: only match bare 'ajv' import, not sub-paths like 'ajv/dist/...'
// (ajv-formats needs real ajv internals for compilation support)
{ find: /^ajv$/, replacement: path.resolve(__dirname, 'src/lib/ajv-csp-safe.js') },
],
},
build: {
// Chrome extensions need to output multiple entry points
rollupOptions: {
input: {
// These will be auto-detected from manifest.json by crx plugin
// but we can add manual chunks if needed
// Manually include sidebar since we removed it from manifest
sidebar: path.resolve(__dirname, 'src/sidebar/index.html'),
// WebMCP content scripts
'content-scripts/webmcp-polyfill': path.resolve(
__dirname,
'src/content-scripts/webmcp-polyfill.js'
),
'content-scripts/page-bridge': path.resolve(
__dirname,
'src/content-scripts/page-bridge.js'
),
'content-scripts/relay': path.resolve(__dirname, 'src/content-scripts/relay.js'),
},
output: {
// Ensure consistent chunk naming
chunkFileNames: 'assets/[name]-[hash].js',
entryFileNames: '[name].js',
assetFileNames: 'assets/[name]-[hash].[ext]',
},
},
// Chrome extensions have stricter CSP, can't use inline scripts
// Only minify for release builds (use RELEASE=1 pnpm run build for production)
minify: process.env.RELEASE ? 'terser' : false,
terserOptions: process.env.RELEASE
? {
format: {
// Remove all comments in production
comments: false,
},
}
: undefined,
// Generate source maps for dev, exclude for release (smaller package, protects source)
sourcemap: !process.env.RELEASE,
},
server: {
port: 5173,
strictPort: true,
hmr: {
port: 5173,
},
},
// Chrome extension specific optimizations
optimizeDeps: {
// With our CSP-safe ajv shim, we can pre-bundle normally
},
});