-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
75 lines (67 loc) · 1.92 KB
/
vite.config.ts
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
66
67
68
69
70
71
72
73
74
75
/// <reference types="vitest" />
import { preact } from '@preact/preset-vite';
import { default as typescript } from '@rollup/plugin-typescript';
import { readFile } from 'fs/promises';
import { createRequire } from 'module';
import { fileURLToPath } from 'url';
import { AliasOptions, defineConfig } from 'vite';
import { checker } from 'vite-plugin-checker';
import { configDefaults } from 'vitest/config';
const { imports }: { imports: Record<string, string> } = JSON.parse(
(await readFile(new URL('./package.json', import.meta.url))).toString(),
);
const isTest = process.env.NODE_ENV === 'test';
const {
coverage: { exclude: coverageExclude = [] },
} = configDefaults;
const generateCjsAlias = (packages: Array<string>) => {
const require = createRequire(import.meta.url);
return packages.map((p) => ({
find: p,
replacement: require.resolve(p),
}));
};
const vitePathAlias: AliasOptions = Object.entries(imports).map(([key, value]) => ({
find: new RegExp(key),
replacement: fileURLToPath(new URL(value.replace('*', ''), import.meta.url)),
}));
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
preact({
include: '{test/,}src/**/*.{ts,tsx}',
}),
!isTest &&
checker({
typescript: { tsconfigPath: 'src/tsconfig.json' },
eslint: {
lintCommand: 'eslint "./src/**/*.{ts,tsx}"',
},
}),
isTest && typescript(),
],
build: {
outDir: fileURLToPath(new URL('./dist/public', import.meta.url)),
emptyOutDir: true,
},
test: {
environment: 'jsdom',
globals: true,
coverage: {
provider: 'istanbul',
exclude: [...coverageExclude, '**/schemas/**'],
},
setupFiles: ['test/testSetup.ts'],
alias: [
...generateCjsAlias([
'preact/hooks',
'@testing-library/preact',
'@tanstack/react-query',
'jotai',
]),
],
},
resolve: {
alias: vitePathAlias,
},
});