-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
89 lines (86 loc) · 2.56 KB
/
vite.config.js
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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import svgr from "vite-plugin-svgr";
import { resolve } from "path";
import fs from "node:fs/promises";
import { devServerHtmlScript } from "./scripts/dev-server-html-script.js";
import { visualizer } from "rollup-plugin-visualizer";
export default defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
const defaultConfig = {
plugins: [
react(),
svgr(),
visualizer({
filename: "dist/stats.html", // Output file for the visualization
template: "treemap", // Other options: sunburst, network
open: true, // Open the visualization in the browser automatically
gzipSize: true, // Display gzip size
brotliSize: true, // Display brotli size
}),
{
name: "index-html-build-replacement",
apply: "serve", // docs:
// https://vitejs.dev/guide/api-plugin.html#conditional-application
async transformIndexHtml(html) {
const tags = [];
if (command === "serve") {
//This is needed for dev server to run see documentation/dev-server-plugin-fix
tags.push({
tag: "script",
attrs: { type: "module" },
children: devServerHtmlScript,
injectTo: "body-prepend",
});
}
switch (mode) {
case "contrast_dev": {
const content = await fs.readFile(
"./index-contrast.html",
"utf8"
);
return { html: content, tags };
}
case "uncontrast_dev": {
const content = await fs.readFile(
"./index-uncontrast.html",
"utf8"
);
return { html: content, tags };
}
}
return html;
},
},
],
};
switch (mode) {
case "contrast_dev":
case "contrast_prod":
return {
...defaultConfig,
build: {
rollupOptions: {
output: {
name: "index",
},
input: resolve(__dirname, "./index-contrast.html"),
},
outDir: "dist-contrast",
name: "index",
},
};
case "uncontrast_prod":
case "uncontrast_dev":
return {
...defaultConfig,
build: {
rollupOptions: {
input: resolve(__dirname, "./index-uncontrast.html"),
},
outDir: "dist-uncontrast",
},
};
default:
return defaultConfig;
}
});