forked from Such-Software/smirk-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
97 lines (91 loc) · 3.13 KB
/
vite.config.ts
File metadata and controls
97 lines (91 loc) · 3.13 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { defineConfig } from 'vite';
import { resolve } from 'path';
import { copyFileSync, mkdirSync, readdirSync, statSync } from 'fs';
function copyDirRecursive(src: string, dest: string) {
mkdirSync(dest, { recursive: true });
for (const entry of readdirSync(src)) {
const srcPath = `${src}/${entry}`;
const destPath = `${dest}/${entry}`;
if (statSync(srcPath).isDirectory()) {
copyDirRecursive(srcPath, destPath);
} else {
copyFileSync(srcPath, destPath);
}
}
}
function copyStaticAssets() {
return {
name: 'copy-static-assets',
writeBundle() {
// Copy manifest.json
copyFileSync('manifest.json', 'dist/manifest.json');
// Copy icons (recursively to handle subdirs like coins/)
copyDirRecursive('icons', 'dist/icons');
// Copy smirk-wasm files (Monero key image verification)
mkdirSync('dist/wasm', { recursive: true });
const wasmPkgDir = '../smirk-wasm-monero/pkg';
try {
copyFileSync(`${wasmPkgDir}/smirk_wasm.js`, 'dist/wasm/smirk_wasm.js');
copyFileSync(`${wasmPkgDir}/smirk_wasm_bg.wasm`, 'dist/wasm/smirk_wasm_bg.wasm');
} catch (e) {
console.warn('Warning: Could not copy smirk-wasm files. Build smirk-wasm first.');
}
// Copy Grin WASM and JS files
mkdirSync('dist/src/lib/grin', { recursive: true });
const grinDir = 'src/lib/grin';
try {
for (const file of readdirSync(grinDir)) {
if (file.endsWith('.wasm') || file.endsWith('.js')) {
copyFileSync(`${grinDir}/${file}`, `dist/src/lib/grin/${file}`);
}
}
} catch (e) {
console.warn('Warning: Could not copy Grin files.', e);
}
},
};
}
export default defineConfig({
build: {
outDir: 'dist',
emptyOutDir: true,
// Disable modulepreload polyfill - it tries to access document which doesn't exist in service workers
modulePreload: false,
rollupOptions: {
input: {
popup: resolve(__dirname, 'popup.html'),
background: resolve(__dirname, 'src/background/index.ts'),
content: resolve(__dirname, 'src/content/index.ts'),
inject: resolve(__dirname, 'src/inject/smirk-api.ts'),
},
output: {
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash][extname]',
// Content scripts and inject scripts can't use ES module imports,
// so we need to inline shared code into them
manualChunks(id) {
// Don't create chunks for content script dependencies - inline them
// Only create chunks for popup and background shared code
if (id.includes('node_modules')) {
// Allow chunking for popup dependencies (preact, etc.)
if (id.includes('preact') || id.includes('@noble')) {
return undefined; // Let Vite decide
}
}
return undefined;
},
},
},
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
plugins: [copyStaticAssets()],
esbuild: {
jsx: 'automatic',
jsxImportSource: 'preact',
},
});