-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
64 lines (60 loc) · 2.41 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
import { svelte } from "@sveltejs/vite-plugin-svelte";
import * as path from "path";
import { defineConfig } from "vite";
import svelteConfig from "./svelte.config.js";
const MANUAL_CHUNKS = new Map([
// game: chunk for game mode utils to avoid circular dependencies between game modes and site
["src/modules/rng.ts", "game"],
["src/modules/canvasUtil.ts", "game"],
["src/modules/gameHandler.ts", "game"],
["src/data/gamepool.ts", "game"],
["src/data/gamepool.json", "game"],
// albumpool: chunk for album data, it's the biggest file on the site, keep it seperate in case of updates
["src/data/albumpool.ts", "albumpool"],
["src/data/albumpool.json", "albumpool"],
// daily: chunk for rolling code, as rerolls might be updated almost daily - improve cache efficiency
["src/modules/daily.ts", "daily"],
["src/stores/state.ts", "daily"],
["src/data/rerolls.ts", "daily"],
// Avoid bundling other modules in the daily chunk - keep it as small as possible
["src/stores/statistics.ts", "site"],
]);
export default defineConfig(() => ({
plugins: [svelte(svelteConfig)],
resolve: {
alias: {
$actions: path.resolve(__dirname, "./src/actions"),
$data: path.resolve(__dirname, "./src/data"),
$icon: path.resolve(__dirname, "./src/icon"),
$lib: path.resolve(__dirname, "./src/lib"),
$modules: path.resolve(__dirname, "./src/modules"),
$stores: path.resolve(__dirname, "./src/stores"),
},
},
build: {
assetsDir: "bundles",
rollupOptions: {
output: {
manualChunks: (id) => {
// Seperate chunk for node_modules
if (id.indexOf("node_modules") !== -1) {
return "vendor";
}
for (const [filename, chunkName] of MANUAL_CHUNKS) {
if (id.endsWith(filename)) {
return chunkName;
}
}
// All code but App.svelte (and entry points) goes into a separate chunk called site
if (id.indexOf("/src/lib") !== -1) {
return "site";
}
return; // default vite chunking
},
},
},
},
define: {
VITE_DEFINE_BUILDTIME: Date.now(),
},
}));