-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
52 lines (48 loc) · 1.34 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
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import packageJSON from './package.json'
const separators = new RegExp(/[-_/]+/, 'g')
const nonWord = new RegExp(/[^\w\s]/, 'g')
const firstLetterAfterSpace = new RegExp(/\s+(.)(\w*)/, 'g')
const word = new RegExp(/\w/)
// From https://stackoverflow.com/questions/4068573/convert-string-to-pascal-case-aka-uppercamelcase-in-javascript
function toPascalCase(text: string) {
return text
.toLowerCase()
.replace(separators, ' ')
.replace(nonWord, '')
.replace(
firstLetterAfterSpace,
(_, $2: string, $3: string) => `${$2.toUpperCase() + $3}`
)
.replace(word, (s) => s.toUpperCase())
}
export default defineConfig({
build: {
minify: false,
lib: {
entry: ['src/globcat.ts', 'src/globcat-bin.ts'],
name: toPascalCase(packageJSON.name)
},
rollupOptions: {
external: [/^node:/, ...Object.keys(packageJSON.dependencies)],
plugins: [nodeResolve()],
output: {
dir: 'dist',
banner(chunkInfo) {
if (chunkInfo.name === 'globcat-bin') {
return '#! /usr/bin/env node\n'
}
return ''
}
}
}
},
plugins: [
dts({
rollupTypes: true,
exclude: ['**/vite-env.d.ts']
})
]
})