Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
103 lines (94 loc) · 2.28 KB
/
Copy pathvite.config.ts
File metadata and controls
103 lines (94 loc) · 2.28 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
import path from "node:path";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { defineConfig, transformWithEsbuild } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
const rootDir = path.dirname(fileURLToPath(import.meta.url));
const appVersion = (
JSON.parse(
readFileSync(path.join(rootDir, "package.json"), "utf8"),
) as { version: string }
).version;
type Distribution = "datasance" | "iofog";
function resolveDistribution(): Distribution {
return process.env.VITE_DISTRIBUTION === "iofog" ? "iofog" : "datasance";
}
function controllerConfigCacheBust() {
return {
name: "controller-config-cache-bust",
transformIndexHtml(html: string) {
return html.replace(
'src="/controller-config.js"',
`src="/controller-config.js?v=${appVersion}"`,
);
},
};
}
function distributionBranding() {
const distribution = resolveDistribution();
const faviconHref =
distribution === "iofog"
? "/branding/iofog/favicon.ico"
: "/branding/datasance/favicon.ico";
const manifestHref =
distribution === "iofog"
? "/branding/iofog/manifest.json"
: "/branding/datasance/manifest.json";
return {
name: "distribution-branding",
transformIndexHtml(html: string) {
return html
.replace(
'href="/branding/datasance/favicon.ico"',
`href="${faviconHref}"`,
)
.replace(
'href="/branding/datasance/manifest.json"',
`href="${manifestHref}"`,
);
},
};
}
function jsxInJs() {
return {
name: "jsx-in-js",
enforce: "pre" as const,
async transform(code: string, id: string) {
if (!/\/src\/.*\.js$/.test(id)) {
return null;
}
return transformWithEsbuild(code, id, {
loader: "jsx",
jsx: "automatic",
});
},
};
}
export default defineConfig({
plugins: [
controllerConfigCacheBust(),
distributionBranding(),
jsxInJs(),
react(),
tailwindcss(),
],
resolve: {
alias: {
"@": path.resolve(rootDir, "src"),
},
},
optimizeDeps: {
esbuildOptions: {
loader: {
".js": "jsx",
},
},
},
build: {
outDir: "build",
},
server: {
port: 3000,
},
});