-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
vite.config.ts
50 lines (43 loc) · 1.38 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
import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";
import UnoCSS from "unocss/vite";
import metadata from "./public/client-metadata.json";
const SERVER_HOST = "127.0.0.1";
const SERVER_PORT = 13213;
export default defineConfig({
plugins: [
UnoCSS(),
solidPlugin(),
// Injects OAuth-related variables
{
name: "oauth",
config(_conf, { command }) {
if (command === "build") {
process.env.VITE_OAUTH_CLIENT_ID = metadata.client_id;
process.env.VITE_OAUTH_REDIRECT_URL = metadata.redirect_uris[0];
} else {
const redirectUri = ((): string => {
const url = new URL(metadata.redirect_uris[0]);
return `http://${SERVER_HOST}:${SERVER_PORT}${url.pathname}`;
})();
const clientId =
`http://localhost` +
`?redirect_uri=${encodeURIComponent(redirectUri)}` +
`&scope=${encodeURIComponent(metadata.scope)}`;
process.env.VITE_DEV_SERVER_PORT = "" + SERVER_PORT;
process.env.VITE_OAUTH_CLIENT_ID = clientId;
process.env.VITE_OAUTH_REDIRECT_URL = redirectUri;
}
process.env.VITE_CLIENT_URI = metadata.client_uri;
process.env.VITE_OAUTH_SCOPE = metadata.scope;
},
},
],
server: {
host: SERVER_HOST,
port: SERVER_PORT,
},
build: {
target: "esnext",
},
});