-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
65 lines (57 loc) · 1.78 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
65
import react from "@vitejs/plugin-react";
import { ProxyOptions, defineConfig } from "vite";
import { join } from "path";
import { readdirSync, writeFileSync } from "fs";
const sourceFolders = ["v1", "v10_5", "v10_6", "v10_7"];
const chartPackages = sourceFolders.flatMap((srcPath) =>
readdirSync(join("src", srcPath), { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => ({ name: dirent.name, folder: srcPath }))
);
const port = process.env.port || 3002; // Default to port 3002 if PORT environment variable is not set
const hostURL = `http://localhost:${port}`;
// ProxyOption used for correct route instead of absolute path URL
const proxyOption = {};
const urls = chartPackages.map(({ name: folder, folder: srcPath }) => {
const pathKey = `/${srcPath}/${folder}`;
const targetUrl = `${hostURL}/${srcPath}/${folder}/`;
proxyOption[pathKey] = {
target: targetUrl,
changeOrigin: true,
rewrite: (path) => path.replace(pathKey, ""),
ignorePath: true,
} as ProxyOptions;
return {
name: folder,
sourceUrl: `${hostURL}/${srcPath}/${folder}/`,
};
});
// Write the JSON file
// Check generated_urls.json for all generated URLS
const jsonFilePath = join(__dirname, "generated_urls.json");
writeFileSync(jsonFilePath, JSON.stringify(urls, null, 2));
export default defineConfig({
// base: './',
root: "src",
plugins: [react()],
optimizeDeps: {
esbuildOptions: {
treeShaking: true,
},
},
build: {
outDir: "../dist",
rollupOptions: {
input: chartPackages.reduce(
(entries, { name: folder, folder: srcPath }) => {
entries[folder] = join("src", srcPath, `/${folder}/index.html`);
return entries;
},
{}
),
},
},
server: {
proxy: proxyOption,
},
});