-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathvite.config.ts
More file actions
42 lines (38 loc) · 1.14 KB
/
vite.config.ts
File metadata and controls
42 lines (38 loc) · 1.14 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
import { defineConfig, Plugin } from "vite";
import react from "@vitejs/plugin-react";
import { viteSingleFile } from "vite-plugin-singlefile";
import { resolve } from "path";
// Get the app to build from environment variable
const app = process.env.APP;
if (!app) {
throw new Error("APP environment variable must be set");
}
// Plugin to rename the output file and remove the nested directory structure
function renameOutput(): Plugin {
return {
name: "rename-output",
enforce: "post",
generateBundle(_, bundle) {
// Find the HTML file and rename it
for (const fileName of Object.keys(bundle)) {
if (fileName.endsWith("index.html")) {
const chunk = bundle[fileName];
chunk.fileName = `${app}.html`;
delete bundle[fileName];
bundle[`${app}.html`] = chunk;
break;
}
}
},
};
}
export default defineConfig({
plugins: [react(), viteSingleFile(), renameOutput()],
build: {
outDir: resolve(__dirname, "../pkg/github/ui_dist"),
emptyOutDir: false,
rollupOptions: {
input: resolve(__dirname, `src/apps/${app}/index.html`),
},
},
});