-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
43 lines (35 loc) · 1.04 KB
/
tsdown.config.ts
File metadata and controls
43 lines (35 loc) · 1.04 KB
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
import { type InternalModuleFormat } from 'rolldown'
import { defineConfig } from 'tsdown'
import packageJSON from './package.json' with { type: 'json' }
export default defineConfig({
entry: {
index: './src/index.ts',
},
outDir: './dist',
tsconfig: './tsconfig.json',
format: ['cjs', 'es'] satisfies InternalModuleFormat[],
dts: true,
sourcemap: true,
target: 'ES6',
minify: 'dce-only',
external: [
/node:/gim,
/node_modules/gim,
...getExternal((packageJSON as any).dependencies),
...getExternal((packageJSON as any).devDependencies),
...getExternal((packageJSON as any).peerDependencies),
],
outputOptions(options, format) {
const ext = format === 'cjs' ? 'cjs' : format === 'es' ? 'mjs' : 'js'
return {
...options,
entryFileNames: `[name].${ext}`,
chunkFileNames: `__[name].[hash].${ext}`,
}
},
})
function getExternal(dependencies: unknown) {
return Object.keys((dependencies ?? {}) as Record<string, string>).map(
(dep) => new RegExp(`(^${dep}$)|(^${dep}/)`)
)
}