-
Notifications
You must be signed in to change notification settings - Fork 55
/
vite.config.ts
66 lines (61 loc) · 1.66 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
import { readFile } from 'node:fs/promises';
import { fileURLToPath, pathToFileURL } from 'node:url';
import reactPlugin from '@vitejs/plugin-react';
import type { PackageJson } from 'type-fest';
import { defineConfig } from 'vite';
import { constructCss, loadRegisterJs } from './scripts/vite/plugins.js';
import { loadMockConfig } from './scripts/vite/test-utils.js';
const root = new URL('./', import.meta.url);
const cwd = pathToFileURL(`${process.cwd()}/`);
const [packageJson, mocks] = await Promise.all([
readFile(new URL('./package.json', cwd), 'utf8').then((content) => JSON.parse(content) as PackageJson),
loadMockConfig({ cwd }),
]);
export default defineConfig({
build: {
target: 'esnext',
},
cacheDir: '.vite',
esbuild: {
define: {
__NAME__: JSON.stringify(packageJson.name ?? '@hilla/unknown'),
__VERSION__: JSON.stringify(packageJson.version ?? '0.0.0'),
},
supported: {
decorators: false,
'top-level-await': true,
},
},
plugins: [
loadRegisterJs({ root }),
constructCss(),
reactPlugin({
include: '**/*.tsx',
babel: {
plugins: [
[
'module:@preact/signals-react-transform',
{
mode: 'all',
},
],
],
},
}),
],
resolve: {
alias: Object.entries(mocks).map(([find, file]) => {
const replacement = fileURLToPath(new URL(`test/mocks/${file}`, cwd));
return {
customResolver(_, importer) {
if (importer?.includes('/mocks/')) {
return false;
}
return replacement;
},
find,
replacement,
};
}),
},
});