-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.ts
79 lines (70 loc) · 1.79 KB
/
vite.config.ts
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
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
import { readFileSync } from 'fs';
import { join, resolve } from 'path';
const network = process.env.DFX_NETWORK ?? 'local';
const readCanisterIds = ({ prefix }: { prefix?: string }): Record<string, string> => {
const canisterIdsJsonFile =
network === 'ic'
? join(process.cwd(), 'canister_ids.json')
: join(process.cwd(), '.dfx', 'local', 'canister_ids.json');
try {
type Details = {
ic?: string;
local?: string;
};
const config: Record<string, Details> = JSON.parse(readFileSync(canisterIdsJsonFile, 'utf-8'));
return Object.entries(config).reduce((acc, current: [string, Details]) => {
const [canisterName, canisterDetails] = current;
return {
...acc,
[`${prefix ?? ''}${canisterName.toUpperCase()}_CANISTER_ID`]:
canisterDetails[network as keyof Details]
};
}, {});
} catch (e) {
throw Error(`Could not get canister ID from ${canisterIdsJsonFile}: ${e}`);
}
};
export default defineConfig({
plugins: [sveltekit()],
build: {
target: 'esnext',
},
resolve: {
alias: {
$declarations: resolve('./src/declarations')
}
},
server: {
proxy: {
'/api': 'http://localhost:8080'
}
},
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
},
// Enable esbuild polyfill plugins
plugins: [
// @ts-ignore
NodeModulesPolyfillPlugin(),
{
name: 'fix-node-globals-polyfill',
setup(build) {
build.onResolve({ filter: /_virtual-process-polyfill_\.js/ }, ({ path }) => ({ path }));
}
}
]
}
},
define: {
'process.env': {
...readCanisterIds({}),
DFX_NETWORK: network
}
}
});