-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathbuild.config.ts
40 lines (39 loc) · 1.09 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
import fs from 'node:fs/promises'
import { defineBuildConfig } from 'unbuild'
export default defineBuildConfig({
entries: ['src/index'],
externals: ['vite'],
clean: true,
declaration: true,
rollup: {
emitCJS: true,
inlineDependencies: true,
esbuild: {
target: 'node18',
},
output: {
generatedCode: {
reservedNamesAsProps: false,
},
},
},
hooks: {
async 'build:done'(ctx) {
// Remove duplicated `dist/chunks/certificate.{cjs,mjs}` chunks
// as both are only dynamically imported by the entrypoints. The
// dynamic import can use the `.mjs` chunk only instead.
await fs.rm('dist/chunks/certificate.cjs')
const indexCjs = await fs.readFile('dist/index.cjs', 'utf8')
const editedIndexCjs = indexCjs.replace(
'chunks/certificate.cjs',
'chunks/certificate.mjs',
)
if (indexCjs === editedIndexCjs) {
throw new Error(
'Failed to find `dist/chunks/certificate.cjs` in `dist/index.cjs`',
)
}
await fs.writeFile('dist/index.cjs', editedIndexCjs)
},
},
})