headplane/vite.config.ts

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-03-11 22:44:23 -04:00
import { readFile } from 'node:fs/promises';
2024-12-31 10:30:14 +05:30
import { reactRouter } from '@react-router/dev/vite';
2025-05-29 09:45:47 -04:00
import tailwindcss from '@tailwindcss/vite';
2025-03-20 15:31:06 -04:00
import { reactRouterHonoServer } from 'react-router-hono-server/dev';
2024-12-31 10:30:14 +05:30
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
import { parse } from 'yaml';
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');
}
2025-03-11 22:44:23 -04:00
// Load the version via package.json
const pkg = await readFile('package.json', 'utf-8');
const isNext = process.env.IMAGE_TAG?.includes('next');
2025-03-11 22:44:23 -04:00
const { version } = JSON.parse(pkg);
if (!version) {
2025-03-11 22:44:23 -04:00
throw new Error('Unable to read version from package.json');
}
// Load the config without any environment variables (not needed here)
const config = await readFile('config.example.yaml', 'utf-8');
const { server } = parse(config);
2025-03-24 16:26:47 -04:00
export default defineConfig(({ isSsrBuild }) => ({
base: `${prefix}/`,
2025-05-29 09:45:47 -04:00
plugins: [
reactRouterHonoServer(),
reactRouter(),
tailwindcss(),
tsconfigPaths(),
],
server: {
host: server.host,
port: server.port,
},
ssr: {
target: 'node',
2025-06-20 11:32:27 -04:00
noExternal: isSsrBuild ? ['@libsql/client'] : undefined,
},
optimizeDeps: {
include: ['@libsql/client'],
},
define: {
__VERSION__: JSON.stringify(isNext ? `${version}-next` : version),
__PREFIX__: JSON.stringify(prefix),
},
2025-03-24 16:26:47 -04:00
}));