forked from ShokoAnime/Shoko-WebUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mjs
65 lines (56 loc) · 1.63 KB
/
vite.config.mjs
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 path from 'path';
import { writeFile } from 'fs/promises';
import childProcess from 'child_process';
import pkg from './package.json';
import { defineConfig } from 'vite';
import { sentryVitePlugin } from '@sentry/vite-plugin';
import react from '@vitejs/plugin-react';
export default defineConfig(async () => {
const isDebug = process.env.NODE_ENV !== 'production';
const version = await setupEnv(isDebug);
let proxy = {};
try {
proxy = await import('./proxy.config');
} catch {}
let sentryPlugin;
if (process.env.SENTRY_AUTH_TOKEN) {
sentryPlugin = sentryVitePlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: 'shoko-anime',
project: 'shoko-webui',
release: {
name: isDebug ? 'dev' : `shoko-webui@${version}`,
},
include: './dist',
urlPrefix: '~/webui/dist/',
ignore: [],
});
}
return {
server: {
open: "/webui/",
port: 3000,
proxy,
},
resolve: {
alias: [
{ find: '@', replacement: path.resolve(__dirname, 'src') },
],
},
build: {
sourcemap: true,
chunkSizeWarningLimit: 2000
},
plugins: [react(), sentryPlugin],
base: "/webui/"
};
});
async function setupEnv(isDebug) {
const gitHash = childProcess.execSync("git log --pretty=format:'%h' -n 1").toString().replace(/["']/g, '');
const appVersion = pkg.version;
process.env.VITE_GITHASH = gitHash;
process.env.VITE_APPVERSION = appVersion;
const output = JSON.stringify({ git: gitHash, package: appVersion, debug: isDebug }, null, ' ');
await writeFile('./public/version.json', output, 'utf8');
return appVersion;
}