-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathvite.config.ts
More file actions
123 lines (122 loc) · 3.67 KB
/
vite.config.ts
File metadata and controls
123 lines (122 loc) · 3.67 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import config from "config";
import path from "node:path";
import { defineConfig } from "vitest/config";
import { svelte } from "@sveltejs/vite-plugin-svelte";
export default defineConfig({
define: {
buildTimeConfig: JSON.stringify(config.util.toObject()),
},
test: {
environment: "happy-dom",
include: ["tests/unit/**/*.test.ts"],
reporters: "verbose",
},
plugins: [
svelte({
// Reference: https://github.com/sveltejs/vite-plugin-svelte/issues/270#issuecomment-1033190138
dynamicCompileOptions({ filename }) {
if (
path.basename(filename) === "Clipboard.svelte" ||
path.basename(filename) === "ExternalLink.svelte" ||
path.basename(filename) === "Icon.svelte"
) {
return { customElement: true };
}
},
compilerOptions: { dev: process.env.NODE_ENV !== "production" },
}),
{
name: "inject-config-loader",
transformIndexHtml() {
if (process.env.VITE_RUNTIME_CONFIG === "true") {
return [
{
tag: "script",
attrs: {
type: "text/javascript",
},
children: `
try {
const xhr = new XMLHttpRequest();
xhr.open("GET", "/config.json", false);
xhr.send(null);
window.__CONFIG__ = JSON.parse(xhr.responseText);
} catch {
console.warn("Couldn't load config.json from the server, using built-in fallback config.");
}
`,
injectTo: "head-prepend",
},
];
}
},
},
],
optimizeDeps: {
include: [
"@wooorm/starry-night",
"@wooorm/starry-night/etc",
"@wooorm/starry-night/go.mod",
"@wooorm/starry-night/go.sum",
"@wooorm/starry-night/source.batchfile",
"@wooorm/starry-night/source.dockerfile",
"@wooorm/starry-night/source.dotenv",
"@wooorm/starry-night/source.editorconfig",
"@wooorm/starry-night/source.erlang",
"@wooorm/starry-night/source.git-revlist",
"@wooorm/starry-night/source.gitattributes",
"@wooorm/starry-night/source.gitconfig",
"@wooorm/starry-night/source.gitignore",
"@wooorm/starry-night/source.groovy.gradle",
"@wooorm/starry-night/source.haproxy-config",
"@wooorm/starry-night/source.ini.npmrc",
"@wooorm/starry-night/source.json",
"@wooorm/starry-night/source.nix",
"@wooorm/starry-night/source.sass",
"@wooorm/starry-night/source.solidity",
"@wooorm/starry-night/source.svelte",
"@wooorm/starry-night/source.toml",
"@wooorm/starry-night/source.tsx",
"@wooorm/starry-night/source.zig",
"@wooorm/starry-night/text.html.asciidoc",
"@wooorm/starry-night/text.html.django",
"@wooorm/starry-night/text.html.vue",
"@wooorm/starry-night/text.robots-txt",
"@wooorm/starry-night/text.zone_file",
],
},
server: {
host: "localhost",
port: 3000,
watch: {
// reference: https://stackoverflow.com/a/75238360
useFsEvents: false,
},
},
resolve: {
alias: {
"@app": path.resolve("./src"),
"@public": path.resolve("./public"),
"@http-client": path.resolve("./http-client"),
"@tests": path.resolve("./tests"),
},
},
build: {
outDir: "build",
rollupOptions: {
output: {
manualChunks: id => {
if (id.includes("lodash")) {
return "lodash";
} else if (id.includes("katex")) {
return "katex";
} else if (id.includes("node_modules")) {
return "vendor";
} else if (id.includes("components")) {
return "components";
}
},
},
},
},
});