-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ts
59 lines (52 loc) · 1.53 KB
/
build.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
57
58
59
import { build, type Options } from 'tsup'
import { writeFile } from 'fs/promises'
import { generateDtsBundle } from 'dts-bundle-generator'
import { dirname, join } from 'path'
import { mkdir } from 'fs/promises'
import { existsSync } from 'fs'
import { rm } from 'fs/promises'
if (existsSync('JsxSSR.d.ts')) await rm('JsxSSR.d.ts', { recursive: true })
if (existsSync('cjs')) await rm('cjs', { recursive: true })
if (existsSync('esm')) await rm('esm', { recursive: true })
const sharedConfig: Options = {
platform: 'node',
entry: ['src/JsxSSR.ts'],
bundle: true,
minify: true,
minifyIdentifiers: true,
minifySyntax: true,
minifyWhitespace: true,
skipNodeModulesBundle: true,
clean: true,
dts: false
}
await build({
format: 'cjs',
outDir: 'cjs',
tsconfig: './tsconfig.cjs.json',
splitting: false,
shims: true,
...sharedConfig
})
await build({
format: ['esm'],
outDir: 'esm',
tsconfig: './tsconfig.mjs.json',
splitting: true,
cjsInterop: false,
...sharedConfig
})
await writeFile('cjs/package.json', JSON.stringify({ type: 'commonjs' }, null, 2))
await writeFile('esm/package.json', JSON.stringify({ type: 'module' }, null, 2))
const dtsPath = join(process.cwd(), 'JsxSSR.d.ts')
const dtsCode = generateDtsBundle([{
filePath: join(process.cwd(), 'src/JsxSSR.ts'),
output: {
sortNodes: true,
exportReferencedTypes: true,
inlineDeclareExternals: true,
inlineDeclareGlobals: true
}
}])
await mkdir(dirname(dtsPath), { recursive: true })
await writeFile(dtsPath, dtsCode, { encoding: 'utf-8' })