-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsup.config.ts
56 lines (43 loc) · 1.36 KB
/
tsup.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
53
54
55
56
import path from 'path'
import fs from 'fs'
import { defineConfig } from 'tsup'
const pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json')).toString())
export default defineConfig({
// your entry file, can also use regexp like
// ['src/index.ts', 'src/components/**/*.{ts,tsx}', '!src/components/**/*.stories.*']
// to include all ts,tsx under components but stories.
entry: ['src/index.ts'],
sourcemap: true,
clean: true,
// exclude all dependencies specified in package.json
external: Object.keys(pkg),
// auto generate types.d.ts
dts: true,
// esm for import, cjs for require
format: ['esm', 'cjs'],
minify: true,
// make sure treeshake works
treeshake: true,
outDir: 'dist',
// onSuccess callback
async onSuccess() {
// manual cleanup empty folders, because `clean` flag wont do this
cleanupEmptyFolders(path.resolve('dist'))
},
})
function cleanupEmptyFolders(folder: string) {
if (!fs.statSync(folder).isDirectory()) {
return
}
let files = fs.readdirSync(folder)
if (files.length > 0) {
files.forEach((file) => cleanupEmptyFolders(path.join(folder, file)))
// Re-evaluate files; after deleting subfolders we may have an empty parent
// folder now.
files = fs.readdirSync(folder)
}
if (files.length == 0) {
console.log('removing: ', folder)
fs.rmdirSync(folder)
}
}