headplane/vite.config.ts
Igor Ramazanov 8268de92c4 feat: do not rely on git for versioning
It causes lots of pain when building with `nix` for a local `flake.nix`.

Not sure if it's a good general solution:
* now it requires a manual step of updating `./version` on each release.
* we're losing commit hash abbreviation, like `0.5.3-5-gbe5a291`

I guess, this can be fixed by installing git-pre-commit-hook, but even
then it'd be wrong, because the output of `git describe --tags --always`
won't be the same before and after commit.
2025-03-11 22:49:18 +00:00

32 lines
815 B
TypeScript

import { reactRouter } from '@react-router/dev/vite';
import { defineConfig } from 'vite';
import babel from 'vite-plugin-babel';
import tsconfigPaths from 'vite-tsconfig-paths';
import fs from 'node:fs';
import tailwindcss from 'tailwindcss';
import autoprefixer from 'autoprefixer';
const prefix = process.env.__INTERNAL_PREFIX || '/admin';
if (prefix.endsWith('/')) {
throw new Error('Prefix must not end with a slash');
}
const version = fs.readFileSync("version", "utf8");
if (!version) {
throw new Error('Unable to execute git describe');
}
export default defineConfig({
base: `${prefix}/`,
plugins: [reactRouter(), tsconfigPaths()],
css: {
postcss: {
plugins: [tailwindcss, autoprefixer],
},
},
define: {
__VERSION__: JSON.stringify(version),
__PREFIX__: JSON.stringify(prefix),
},
});