-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
93 lines (84 loc) · 1.84 KB
/
Copy pathvite.config.ts
File metadata and controls
93 lines (84 loc) · 1.84 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
import { defineConfig } from 'vite';
import { resolve } from 'path';
import { fileURLToPath } from 'url';
import react from '@vitejs/plugin-react';
import dts from 'vite-plugin-dts';
import glob from 'fast-glob';
import { readFileSync } from 'fs';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const pkg = JSON.parse(
readFileSync(resolve(__dirname, 'package.json'), 'utf-8')
);
const entries = glob.sync(['src/**/*.ts', 'src/**/*.tsx'], {
ignore: ['**/*.test.ts', '**/*.spec.ts'],
});
export default defineConfig({
plugins: [
dts({
outDir: 'dist',
}),
react(),
],
// Server configuration for development
server: {
port: 8080,
strictPort: false,
open: false,
},
// Preview configuration
preview: {
port: 8080,
strictPort: false,
},
// Build configuration
build: {
outDir: 'dist',
target: 'es2022',
lib: {
entry: entries.map((e) => resolve(e)),
},
minify: true,
sourcemap: false,
rollupOptions: {
// External dependencies that shouldn't be bundled
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
'react/jsx-runtime',
].map((dep) => new RegExp(`^${dep}(/.*)?$`)),
output: [
{
format: 'es',
entryFileNames: '[name].mjs',
chunkFileNames: '[name].mjs',
preserveModules: true,
dir: 'dist/src',
},
{
format: 'cjs',
entryFileNames: '[name].cjs',
chunkFileNames: '[name].cjs',
preserveModules: true,
dir: 'dist/src',
},
],
},
},
// Module resolution
resolve: {
alias: {
'@': resolve(__dirname, './src'),
},
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
},
// Optimize dependencies
optimizeDeps: {
include: [],
},
// Environment variables
define: {
'process.env.NODE_ENV': JSON.stringify(
process.env['NODE_ENV'] || 'development'
),
},
});