-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathbuild.config.ts
55 lines (53 loc) · 1.25 KB
/
build.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
import { readFile, rm, writeFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
import { resolve } from 'node:path'
import { defineBuildConfig } from 'unbuild'
const lib = fileURLToPath(new URL('./lib', import.meta.url))
export default defineBuildConfig({
declaration: true,
outDir: 'lib',
entries: [
{
name: 'index',
input: 'src/index'
},
{
name: 'types',
input: 'src/types'
},
{
name: 'vite',
input: 'src/vite'
},
{
name: 'webpack',
input: 'src/webpack'
}
],
rollup: {
emitCJS: true
},
externals: ['vite', 'webpack'],
hooks: {
'build:done': async () => {
await Promise.all([
rm(resolve(lib, 'types.cjs')),
rm(resolve(lib, 'types.mjs')),
...['vite', 'webpack'].map(async name => {
for (const ext of ['d.ts', 'd.cts']) {
const path = resolve(lib, `${name}.${ext}`)
const content = await readFile(path, 'utf-8')
await writeFile(
path,
content.replace(
`export { ${name} as default };`,
`export = ${name};`
),
{ encoding: 'utf-8' }
)
}
})
])
}
}
})