-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvite.config.js
89 lines (86 loc) · 2.53 KB
/
vite.config.js
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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsconfigPaths from 'vite-tsconfig-paths';
import svgrPlugin from 'vite-plugin-svgr';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import EnvironmentPlugin from 'vite-plugin-environment';
import path from 'path';
// Get require functionality in ESM
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
function rewriteUrlWithExtension(url, fileName) {
if (url.match(new RegExp(`^/${fileName}($|\\?)`))) {
return url.replace(new RegExp(`^/${fileName}`), `/${fileName}.html`);
}
return url;
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
viteTsconfigPaths(),
svgrPlugin(),
EnvironmentPlugin({
ETHEREUM_CHAIN_ID: 1,
AZTEC_CHAIN_ID: 677868, // TODO remove this
NODE_ENV: 'production',
ROLLUP_HOST: 'https://api.aztec.network/aztec-connect-prod/falafel',
WALLETCONNECT_PROJECT_ID: process.env.WALLETCONNECT_PROJECT_ID,
}),
viteStaticCopy({
targets: [
{
src: `${path.dirname(require.resolve('@aztec/alpha-sdk'))}/aztec-connect.wasm`,
dest: '',
},
{
src: `${path.dirname(require.resolve('@aztec/alpha-sdk'))}/web_worker.js`,
dest: '',
},
],
}),
{
name: 'configure-server',
configureServer(server) {
server.middlewares.use((req, _, next) => {
['wc', 'iframe', 'popup'].forEach(fileName => {
req.url = rewriteUrlWithExtension(req.url, fileName);
});
next();
});
},
},
],
resolve: {
alias: { buffer: 'buffer/' },
},
build: {
outDir: 'dest',
rollupOptions: {
input: {
iframe: path.resolve(__dirname, 'src/iframe/main.tsx'),
popup: path.resolve(__dirname, 'src/popup/main.tsx'),
standalone: path.resolve(__dirname, 'src/standalone/main.tsx'),
'iframe-index': path.resolve(__dirname, 'iframe.html'),
'popup-index': path.resolve(__dirname, 'popup.html'),
wc: path.resolve(__dirname, 'wc.html'),
},
},
commonjsOptions: {
transformMixedEsModules: true, // Enable @walletconnect/web3-provider which has some code in CommonJS
},
},
optimizeDeps: {
// NOTE: fixes locally linked aztec-ui, but only for dev builds
include: ['@aztec/aztec-ui'],
esbuildOptions: {
define: {
global: 'globalThis',
},
},
},
server: {
port: 1235,
host: '0.0.0.0',
},
});