-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.mts
64 lines (58 loc) · 1.44 KB
/
vite.config.mts
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
/// <reference types="vitest" />
import { readFileSync } from 'node:fs'
import { defineConfig } from "vite";
import react from '@vitejs/plugin-react'
import dts from 'vite-plugin-dts'
import tsconfigPaths from 'vite-tsconfig-paths'
const IN_LADLE = process.env['LADLE']
const ext = {
cjs: 'cjs',
es: 'js',
} as const
const packageJson = JSON.parse(readFileSync('./package.json', 'utf-8')) as {
dependencies: Record<string, string>
peerDependencies: Record<string, string>
}
const externalPackages = [
...Object.keys(packageJson.dependencies),
...Object.keys(packageJson.peerDependencies),
/@lexical\/react\/.*/,
'react/jsx-runtime',
'react/jsx-dev-runtime'
]
export default defineConfig({
plugins: [
react(IN_LADLE ? {} : { jsxRuntime: 'classic' } as const),
dts({
rollupTypes: true,
staticImport: true,
compilerOptions: {
skipLibCheck: true,
},
}),
tsconfigPaths()
],
build: {
minify: 'terser',
lib: {
entry: 'src/index.ts',
formats: ['es'],
fileName: (format, entryName) => {
return `${entryName}.${ext[format as 'cjs' | 'es']}`
},
},
rollupOptions: {
output: {
exports: 'named',
preserveModules: true,
preserveModulesRoot: 'src'
},
external: externalPackages,
},
},
test: {
include: ['src/test/**/*.test.{ts,tsx}'],
environment: 'jsdom',
setupFiles: ['src/test/setup.ts'],
},
});