1
Fork 0
href-plus/vite.config.ts

41 lines
1.0 KiB
TypeScript
Raw Normal View History

2021-12-30 22:40:57 +00:00
import childProcess from 'node:child_process';
import path from 'node:path';
import process from 'node:process';
import url from 'node:url';
import {defineConfig} from 'vite';
const currentDir = path.dirname(url.fileURLToPath(import.meta.url));
const buildDir = path.join(currentDir, 'public');
const sourceDir = path.join(currentDir, 'source');
function gitRevParse(): string {
const revParse = childProcess.spawnSync(
'git',
['rev-parse', '--short', '--verify', 'main'],
2022-09-29 14:17:19 +00:00
{encoding: 'utf8'},
2021-12-30 22:40:57 +00:00
);
if (revParse.error) {
throw revParse.error;
}
return JSON.stringify(revParse.stdout.trim());
}
2022-01-06 20:12:20 +00:00
const hrefPlusVersion = process.env.npm_package_version ?? '<unknown version>';
2021-12-30 22:40:57 +00:00
export default defineConfig({
build: {
outDir: buildDir,
sourcemap: true,
},
define: {
2022-01-06 20:12:20 +00:00
hrefPlusVersion: JSON.stringify(hrefPlusVersion),
hrefPlusCommitHash: gitRevParse(),
2022-09-29 14:53:00 +00:00
hrefPlusUserAgent: `"href-plus/${hrefPlusVersion} (https://git.bauke.xyz/Bauke/href-plus)"`,
2021-12-30 22:40:57 +00:00
},
publicDir: path.join(sourceDir, 'assets'),
root: sourceDir,
});