-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtsup.config.ts
40 lines (35 loc) · 1013 Bytes
/
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
import { readFile, writeFile } from 'node:fs/promises'
import { defineConfig } from 'tsup'
async function updateDistFile (
path: string,
mod: string,
template: (mod: string) => string
) {
const dist = await readFile(path, { encoding: 'utf8' })
.then(d => {
return d
.replaceAll(template(`'${mod}'`), template(`'node:${mod}'`))
.replaceAll(template(`"${mod}"`), template(`"node:${mod}"`))
})
await writeFile(path, dist, { encoding: 'utf8' })
}
export default defineConfig({
clean: true,
dts: true,
sourcemap: true,
outDir: 'dist',
format: [
'cjs',
'esm',
],
entry: [
'src/index.ts'
],
async onSuccess() {
const libModules = ['crypto']
for (const mod of libModules) {
await updateDistFile('./dist/index.js', mod, (mod) => `require(${mod})`)
await updateDistFile('./dist/index.mjs', mod, (mod) => `from ${mod}`)
}
},
})