headplane/vite.config.ts

38 lines
1 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-03-11 22:44:23 -04:00
import autoprefixer from 'autoprefixer';
2025-03-20 15:31:06 -04:00
import { reactRouterHonoServer } from 'react-router-hono-server/dev';
2025-03-11 22:44:23 -04:00
import tailwindcss from 'tailwindcss';
2024-12-31 10:30:14 +05:30
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
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 { version } = JSON.parse(pkg);
if (!version) {
2025-03-11 22:44:23 -04:00
throw new Error('Unable to read version from package.json');
}
2025-03-24 16:26:47 -04:00
export default defineConfig(({ isSsrBuild }) => ({
2025-03-22 01:36:27 -04:00
// base: `${prefix}/`,
2025-03-20 15:31:06 -04:00
plugins: [reactRouterHonoServer(), reactRouter(), tsconfigPaths()],
css: {
postcss: {
plugins: [tailwindcss, autoprefixer],
},
},
ssr: {
target: 'node',
2025-03-24 16:26:47 -04:00
noExternal: isSsrBuild ? true : undefined,
},
define: {
__VERSION__: JSON.stringify(version),
__PREFIX__: JSON.stringify(prefix),
},
2025-03-24 16:26:47 -04:00
}));