-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsup.config.ts
45 lines (39 loc) · 1 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
import fs from 'node:fs'
import path from 'node:path'
import { defineConfig } from 'tsup'
const sourceFolder = 'src/templates'
const targetFolder = 'dist/templates'
/*
* https://github.com/egoist/tsup/issues/369
* https://github.com/egoist/tsup/pull/403
*/
export default defineConfig({
entry: {
index: 'src/index.ts',
},
format: ['cjs', 'esm'],
target: 'node18',
splitting: true,
cjsInterop: true,
clean: true,
dts: true,
platform: 'node',
sourcemap: true,
async onSuccess() {
console.log('Build successful-------')
copyFolderSync(sourceFolder, targetFolder)
},
})
function copyFolderSync(source, target) {
if (!fs.existsSync(target))
fs.mkdirSync(target)
const files = fs.readdirSync(source)
files.forEach((file) => {
const currentPath = path.join(source, file)
const targetPath = path.join(target, file)
if (fs.lstatSync(currentPath).isDirectory())
copyFolderSync(currentPath, targetPath)
else
fs.copyFileSync(currentPath, targetPath)
})
}