-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
89 lines (78 loc) · 1.94 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 * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vite';
import solid from 'vite-plugin-solid';
import metadata from './public/oauth/client-metadata.json';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const SERVER_HOST = '127.0.0.1';
const SERVER_PORT = 43818;
export default defineConfig({
build: {
target: 'esnext',
modulePreload: false,
sourcemap: true,
assetsInlineLimit: 0,
minify: 'terser',
terserOptions: {
compress: {
passes: 3,
},
},
},
resolve: {
alias: {
'~': path.join(__dirname, './src'),
},
},
server: {
host: SERVER_HOST,
port: SERVER_PORT,
},
optimizeDeps: {
esbuildOptions: {
target: 'esnext',
},
},
plugins: [
solid({
babel: {
plugins: [['babel-plugin-transform-typescript-const-enums']],
},
}),
// Transform the icon components to remove the `() => _tmpl$()` wrapper
{
transform(code, id) {
if (!id.includes('/icons-central/')) {
return;
}
const transformed = code.replace(
/(?<=createIcon\()\(\)\s*=>*.([\w$]+)\(\)(?=\))/g,
(match, id) => id,
);
return { code: transformed, map: null };
},
},
oauthMetadataPlugin(),
],
});
/**
* @returns {import('vite').Plugin}
*/
function oauthMetadataPlugin() {
return {
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 = `http://${SERVER_HOST}:${SERVER_PORT}/oauth/callback`;
const clientId = `http://localhost?redirect_uri=${encodeURIComponent(redirectUri)}`;
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;
},
};
}