-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.config.ts
executable file
·91 lines (82 loc) · 1.93 KB
/
build.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
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
import { LibraryFormats, build, createServer, InlineConfig } from "vite";
import { rimrafSync } from "rimraf";
import { viteSingleFile } from "vite-plugin-singlefile";
import { parseArgs } from "util";
const {
values: { dev: isDev }
} = parseArgs({
args: process.argv,
options: {
dev: {
type: "boolean"
},
build: {
type: "boolean"
}
},
allowPositionals: true
});
const pluginConfig: InlineConfig = {
build: {
emptyOutDir: false,
outDir: "./metadata",
lib: {
entry: "./src/plugin/index.ts",
fileName: "plugin",
formats: ["es"] as LibraryFormats[]
}
}
};
const panelConfig: InlineConfig = {
root: "./src/panel",
publicDir: "../../metadata",
build: {
outDir: "../../dist",
emptyOutDir: false
},
plugins: [
viteSingleFile(),
{
name: "configure-response-headers",
configureServer: (server) => {
server.middlewares.use((_req, res, next) => {
res.setHeader("Access-Control-Request-Private-Network", "true");
res.setHeader("Access-Control-Allow-Private-Network", "true");
res.setHeader("Access-Control-Expose-Headers", "ETag");
next();
});
}
}
],
server: {
port: 8888,
cors: {
origin: [
"https://qatium.app",
"http://localhost:8888",
"http://localhost:3000",
"null"
],
credentials: true,
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
optionsSuccessStatus: 204
}
}
};
(async () => {
rimrafSync("./metadata/plugin.js");
rimrafSync("./dist");
if (isDev) {
pluginConfig.build!.watch = {};
}
await build(pluginConfig);
await new Promise((resolve) => setTimeout(() => resolve(true), 1000));
if (isDev) {
const server = await createServer(panelConfig);
await server.listen();
server.printUrls();
server.bindCLIShortcuts({ print: true });
} else {
await build(panelConfig);
}
})();