Files
WebDrop/web/vite.config.ts
T
justme 89cd92f7ee
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/push/web-build Pipeline was successful
ci/woodpecker/push/dev-image Pipeline was successful
feat(web): show build info and theme menu [CI]
2026-10-12 16:40:50 +08:00

38 lines
1.4 KiB
TypeScript

import { execFileSync } from 'node:child_process';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vitest/config';
const webRoot = fileURLToPath(new URL('.', import.meta.url));
const webPackage = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')) as { version: string };
function gitValue(...args: string[]): string {
try {
return execFileSync('git', args, { cwd: webRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || 'unknown';
} catch {
return 'unknown';
}
}
const buildInfo = {
frontendVersion: webPackage.version,
commit: process.env.WEBDROP_BUILD_COMMIT ?? gitValue('rev-parse', '--short=12', 'HEAD'),
tag: process.env.WEBDROP_BUILD_TAG ?? gitValue('describe', '--tags', '--exact-match', 'HEAD'),
builtAt: process.env.WEBDROP_BUILD_TIME ?? new Date().toISOString(),
};
export default defineConfig({
plugins: [react()],
define: { __WEBDROP_BUILD_INFO__: JSON.stringify(buildInfo) },
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'@webdrop/core': fileURLToPath(new URL('../packages/core/src/index.ts', import.meta.url)),
},
},
build: { target: 'es2022', sourcemap: false },
server: { proxy: { '/api/v1': { target: 'http://127.0.0.1:5000', ws: true } } },
test: { environment: 'node' },
});