-
Notifications
You must be signed in to change notification settings - Fork 13
/
vite.config.ts
85 lines (80 loc) · 1.9 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
80
81
82
83
84
85
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
import inject from '@rollup/plugin-inject';
import { sveltekit } from '@sveltejs/kit/vite';
import { readFileSync } from 'fs';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { defineConfig, type UserConfig } from 'vite';
const file = fileURLToPath(new URL('package.json', import.meta.url));
const json = readFileSync(file, 'utf8');
const { version } = JSON.parse(json);
const config: UserConfig = {
plugins: [sveltekit()],
resolve: {
alias: {
$declarations: resolve('./src/declarations')
}
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler'
}
}
},
build: {
target: 'es2020',
rollupOptions: {
output: {
manualChunks: (id) => {
const folder = dirname(id);
if (
['@sveltejs', 'svelte', 'layercake'].find((lib) => folder.includes(lib)) ===
undefined &&
folder.includes('node_modules')
) {
return 'vendor';
}
return undefined;
}
},
// Polyfill Buffer for production build
plugins: [
inject({
modules: { Buffer: ['buffer', 'Buffer'] }
})
]
}
},
// Node polyfill agent-js. Thanks solution shared by chovyfu on the Discord channel.
// https://stackoverflow.com/questions/71744659/how-do-i-deploy-a-sveltekit-app-to-a-dfinity-container
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
},
// Enable esbuild polyfill plugins
plugins: [
NodeModulesPolyfillPlugin(),
{
name: 'fix-node-globals-polyfill',
setup(build) {
build.onResolve({ filter: /_virtual-process-polyfill_\.js/ }, ({ path }) => ({ path }));
}
}
]
}
},
worker: {
format: 'es'
}
};
export default defineConfig(
(): UserConfig => ({
...config,
define: {
VITE_APP_VERSION: JSON.stringify(version)
}
})
);