-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvite.config.ts
More file actions
111 lines (98 loc) · 2.54 KB
/
vite.config.ts
File metadata and controls
111 lines (98 loc) · 2.54 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import { resolve } from 'path';
import react from '@vitejs/plugin-react-swc';
import tsconfigPaths from 'vite-tsconfig-paths';
import dts from 'vite-plugin-dts';
import svgr from 'vite-plugin-svgr';
import deletePlugin from 'rollup-plugin-delete';
import terser from '@rollup/plugin-terser';
import { readFileSync } from 'fs';
const packageJson = JSON.parse(readFileSync('./package.json', 'utf-8'));
// Extract dependencies for externalization
const peerDeps = Object.keys(packageJson.peerDependencies || {});
const deps = Object.keys(packageJson.dependencies || {});
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
// React support with SWC
react(),
// TypeScript path mapping
tsconfigPaths(),
// Generate TypeScript declarations
dts({
rollupTypes: false,
insertTypesEntry: true,
include: ['src/**/*'],
exclude: ['src/**/*.test.*', 'src/**/*.spec.*', 'src/**/*.stories.*', 'src/**/*.mdx', 'setupTests.ts'],
tsconfigPath: './tsconfig.json',
outDir: 'dist',
copyDtsFiles: true,
staticImport: true,
logLevel: 'info',
}),
// SVG as React components
svgr({
include: '**/*.svg',
svgrOptions: {
exportType: 'default',
ref: true,
svgo: false,
titleProp: true,
icon: true,
},
}),
// Clean up unwanted files after build
deletePlugin({
targets: ['dist/temp'],
hook: 'writeBundle',
}),
],
resolve: {
alias: {
src: resolve(__dirname, 'src'),
},
},
build: {
outDir: 'dist',
target: 'ES2023',
cssMinify: true,
sourcemap: false,
cssCodeSplit: false,
reportCompressedSize: false,
lib: {
entry: {
main: resolve(__dirname, 'src/index.ts'),
},
name: 'kai-ui',
formats: ['es'],
fileName: () => 'index.js',
},
rollupOptions: {
external: [...peerDeps, ...deps, 'react/jsx-runtime'],
output: {
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
preserveModules: false,
exports: 'named',
inlineDynamicImports: false,
// Minification with terser
plugins: [
terser({
compress: {
drop_console: true,
drop_debugger: true,
passes: 2,
},
mangle: true,
format: {
comments: false,
},
}),
],
},
},
},
});