forked from tale/headplane
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
65 lines (61 loc) · 1.83 KB
/
vite.config.ts
File metadata and controls
65 lines (61 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { readFile } from 'node:fs/promises';
import { reactRouter } from '@react-router/dev/vite';
import tailwindcss from '@tailwindcss/vite';
import { reactRouterHonoServer } from 'react-router-hono-server/dev';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
import { parse } from 'yaml';
const prefix = process.env.__INTERNAL_PREFIX || '/admin';
if (prefix.endsWith('/')) {
throw new Error('Prefix must not end with a slash');
}
// Load the version via package.json
const pkg = await readFile('package.json', 'utf-8');
const isNext = process.env.IMAGE_TAG?.includes('next');
const { version } = JSON.parse(pkg);
if (!version) {
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);
export default defineConfig(({ command, isSsrBuild }) => ({
base: command === 'build' ? `${prefix}/` : undefined,
plugins: [
reactRouterHonoServer(),
reactRouter(),
tailwindcss(),
tsconfigPaths(),
],
server: {
host: server.host,
port: server.port,
},
build: {
target: 'esnext',
sourcemap: true,
rolldownOptions:
command === 'build'
? {
// Exclude libsql from the server side since it's a native module
// Exclude WASM from the client since it fetches from the server
external: isSsrBuild ? [/^@libsql\//] : [/\.wasm(\?url)?$/],
output: {
manualChunks: undefined,
inlineDynamicImports: isSsrBuild,
},
}
: undefined,
},
ssr: {
target: 'node',
noExternal: command === 'build' ? true : undefined,
},
optimizeDeps: {
include: ['@libsql/client'],
},
define: {
__VERSION__: JSON.stringify(isNext ? `${version}-next` : version),
__PREFIX__: JSON.stringify(prefix),
},
}));