-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
101 lines (97 loc) · 2.58 KB
/
vite.config.js
File metadata and controls
101 lines (97 loc) · 2.58 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
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'
export default defineConfig(({ command, mode }) => {
const isLibraryBuild = mode === 'library'
const isNoPackagingBuild = mode === 'noPackaging'
if (isNoPackagingBuild) {
// No packaging build mode: TS->JS without mangling, includes CSS
return {
build: {
lib: {
entry: 'src/kbdmouse.ts',
name: 'KbdMouseJs',
fileName: (format) => `kbdmouse-js.${format}.js`,
formats: ['es'] // Generate only ES modules
},
rollupOptions: {
external: [],
output: {
globals: {},
// Preserve original module names and structure
preserveModules: true,
preserveModulesRoot: 'src',
// No minification or mangling
compact: false,
minifyInternalExports: false,
// Ensure clean module names
entryFileNames: '[name].js',
chunkFileNames: '[name].js'
},
// Preserve module IDs
preserveEntrySignatures: 'strict',
// Include CSS files
plugins: [
{
name: 'css-exporter',
generateBundle(options, bundle) {
// Find and extract CSS
for (const file in bundle) {
if (file.endsWith('.css')) {
// CSS will be automatically extracted by Vite
console.log(`Extracted CSS: ${file}`);
}
}
}
}
]
},
// Disable minification completely
minify: false,
// Generate source maps for debugging
sourcemap: true,
// Copy CSS files as-is
copyPublicDir: true
},
css: {
// Extract CSS to separate files
extract: {
filename: 'kbdmouse-js.css'
}
}
}
}
if (isLibraryBuild) {
// Library mode: minified build for production
return {
build: {
lib: {
entry: 'src/kbdmouse.ts',
name: 'KbdMouseJs',
fileName: (format) => `kbdmouse-js.${format}.js`
},
rollupOptions: {
external: [],
output: {
globals: {}
}
}
},
plugins: [
dts({
include: ['src'],
exclude: ['**/*.css'],
rollupTypes: true
})
]
}
}
// Development mode: includes demo page
return {
build: {
outDir: 'dist'
},
server: {
open: '/examples/index.html'
}
}
})