-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
53 lines (48 loc) · 1.45 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
/// <reference types="vitest" />
import { readdirSync, statSync } from 'fs';
import { resolve } from 'path';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import { externalizeDeps } from 'vite-plugin-externalize-deps';
const normalizeResolve = (...path: string[]) => resolve(__dirname, ...path).replace(/\\/g, '/');
const getPathsRecursively = (baseDir: string): string[] =>
readdirSync(normalizeResolve(baseDir))
.map((p) => normalizeResolve(baseDir, p))
.map((p) => (statSync(p).isDirectory() ? getPathsRecursively(p) : p))
.flat()
.filter((p) => !/(\.spec|test)\.tsx?$/gi.test(p))
.filter((p) => /\.tsx?$/gi.test(p));
const resolveEntryPath = (path: string, baseDir: string) =>
path
.replace(normalizeResolve(baseDir), '')
.replace(/^\//, '')
.replace(/\.tsx?$/g, '');
const getEntryPoints = (baseDir: string) =>
Object.fromEntries(getPathsRecursively(baseDir).map((p) => [resolveEntryPath(p, baseDir), p]));
export default defineConfig({
build: {
outDir: 'dist',
emptyOutDir: true,
lib: {
entry: getEntryPoints('src'),
},
sourcemap: true,
minify: 'esbuild',
},
plugins: [
externalizeDeps(),
dts({
tsConfigFilePath: normalizeResolve('tsconfig.json'),
include: ['src/**/*.{ts,tsx}', 'env.d.ts'],
entryRoot: 'src',
outputDir: 'dist',
}),
],
test: {
environment: 'miniflare',
environmentOptions: {
compatibilityDate: '2023-09-01',
},
setupFiles: [resolve('tests', 'setup.ts')],
},
});