mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 03:23:02 +00:00
feat: show current version (#5)
This commit is contained in:
@@ -1,9 +1,25 @@
|
||||
import path from 'path';
|
||||
import cp from 'node:child_process';
|
||||
import url from 'node:url';
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import wasm from 'vite-plugin-wasm';
|
||||
import replace from '@rollup/plugin-replace';
|
||||
import topLevelAwait from 'vite-plugin-top-level-await';
|
||||
|
||||
const gitRoot = url.fileURLToPath(new URL('.', import.meta.url));
|
||||
const pkg = JSON.parse(fs.readFileSync(gitRoot + '/package.json', 'utf-8'));
|
||||
|
||||
function command(cmd, dir = '') {
|
||||
return cp.execSync(cmd, { cwd: path.join(gitRoot, dir), encoding: 'utf-8' }).trim();
|
||||
}
|
||||
|
||||
const COMMAND_GIT_VERSION = 'git describe --long --dirty --tags --always';
|
||||
const shortCommit = command(COMMAND_GIT_VERSION);
|
||||
const version = `${pkg.version}-${shortCommit}`;
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
server: {
|
||||
@@ -25,7 +41,18 @@ export default defineConfig({
|
||||
optimizeDeps: {
|
||||
exclude: ['@jixun/libparakeet'],
|
||||
},
|
||||
plugins: [react(), wasm(), topLevelAwait()],
|
||||
plugins: [
|
||||
replace({
|
||||
preventAssignment: true,
|
||||
values: {
|
||||
__APP_VERSION_SHORT__: pkg.version,
|
||||
__APP_VERSION__: version,
|
||||
},
|
||||
}),
|
||||
react(),
|
||||
wasm(),
|
||||
topLevelAwait(),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'~': path.resolve(__dirname, 'src'),
|
||||
|
||||
Reference in New Issue
Block a user