-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.js
44 lines (39 loc) · 1.34 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
import { sveltekit } from '@sveltejs/kit/vite';
import svg from '@poppanator/sveltekit-svg';
import { promisify } from 'util';
import { exec } from 'child_process';
const pexec = promisify(exec);
import { hostname } from 'os';
async function getInfo(env, cmd, length = false) {
let value = process.env[env] || (await pexec(cmd)).stdout.trim();
if (length) value = value.substring(0, length);
return value;
}
const commit = await getInfo('VITE_VERCEL_GIT_COMMIT_SHA', 'git rev-parse --short HEAD', 7);
const buildTime = new Date();
export const versionKey = commit + '-' + buildTime.getTime().toString(36); // will be picked by sveltekit
/** @type {import('vite').UserConfig} */
const config = {
define: {
__COMMIT__: JSON.stringify(commit),
__BRANCH__: JSON.stringify(
await getInfo('VITE_VERCEL_GIT_COMMIT_REF', 'git rev-parse --abbrev-ref HEAD')
),
__BUILD_TIME__: JSON.stringify(buildTime.toISOString()),
__BUILD_LOCATION__: JSON.stringify(
(process.env.VERCEL && 'vercel') || process.env.BUILD_LOCATION_NAME || hostname()
),
__WEBPUSH_API_PREFIX__: JSON.stringify(process.env.WEBPUSH_API_PREFIX || ''), // needs a fallback
},
plugins: [sveltekit(), svg()],
server: {
proxy: {
'/api/webpush': 'http://127.0.0.1:6002/',
'/api/pvt': 'http://127.0.0.1:5006/',
},
},
build: {
sourcemap: true,
},
};
export default config;