headplane/vite.config.ts

44 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-12-31 10:30:14 +05:30
import { reactRouter } from '@react-router/dev/vite';
import { defineConfig } from 'vite';
import babel from 'vite-plugin-babel';
import tsconfigPaths from 'vite-tsconfig-paths';
import { execSync } from 'node:child_process';
2024-12-31 10:30:14 +05:30
const prefix = process.env.__INTERNAL_PREFIX || '/admin';
if (prefix.endsWith('/')) {
2024-12-31 10:30:14 +05:30
throw new Error('Prefix must not end with a slash');
}
// Load the version via git tags
2024-12-31 10:30:14 +05:30
const version = execSync('git describe --tags --always').toString().trim();
if (!version) {
2024-12-31 10:30:14 +05:30
throw new Error('Unable to execute git describe');
}
export default defineConfig(({ isSsrBuild }) => {
// If we have the Headplane entry we build it as a single
2024-12-23 10:27:05 -05:00
// server/prod.mjs file that is built for production server bundle
// We know the remix invoked command is vite:build
2024-12-31 10:30:14 +05:30
return {
base: prefix,
build: isSsrBuild ? { target: 'ES2022' } : {},
2024-12-31 10:30:14 +05:30
define: {
__VERSION__: JSON.stringify(version),
},
2024-12-31 10:30:14 +05:30
plugins: [
2024-12-31 10:30:14 +05:30
reactRouter(),
tsconfigPaths(),
babel({
filter: /\.[jt]sx?$/,
babelConfig: {
presets: ['@babel/preset-typescript'],
2024-12-31 10:30:14 +05:30
plugins: [['babel-plugin-react-compiler', {}]],
},
}),
],
2024-12-31 10:30:14 +05:30
};
});