-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathvite.config.shared.ts
More file actions
61 lines (56 loc) · 1.65 KB
/
Copy pathvite.config.shared.ts
File metadata and controls
61 lines (56 loc) · 1.65 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
import { defineConfig, type UserConfig } from 'vite';
type ViteConfigOptions = {
mode: 'lib' | 'ssr';
external: (string | RegExp)[];
banner?: string;
testTimeout?: number;
testPool?: 'threads' | 'forks';
testIsolate?: boolean;
coverage?: UserConfig['test'] extends object ? UserConfig['test']['coverage'] : never;
};
export function createViteConfig(options: ViteConfigOptions): UserConfig {
const { mode, external, banner, testTimeout, testPool, testIsolate, coverage } = options;
const build: UserConfig['build'] =
mode === 'ssr'
? {
ssr: 'src/index.ts',
outDir: 'dist',
emptyOutDir: true,
minify: false,
sourcemap: true,
rolldownOptions: {
output: {
format: 'esm',
entryFileNames: 'index.js',
...(banner ? { banner } : {}),
},
},
}
: {
lib: {
entry: 'src/index.ts',
formats: ['es'],
fileName: 'index',
},
outDir: 'dist',
emptyOutDir: true,
minify: false,
sourcemap: true,
rolldownOptions: {
external,
},
};
const test: UserConfig['test'] = {
globals: true,
include: ['tests/**/*.test.ts'],
...(testTimeout !== undefined ? { testTimeout } : {}),
...(testPool !== undefined ? { pool: testPool } : {}),
...(testIsolate !== undefined ? { isolate: testIsolate } : {}),
...(coverage !== undefined ? { coverage } : {}),
};
return defineConfig({
build,
...(mode === 'ssr' ? { ssr: { target: 'node', external } } : {}),
test,
});
}