Repository navigation
Expand file tree
/
Copy pathtsdown.config.mjs
More file actions
68 lines (63 loc) · 1.76 KB
/
Copy pathtsdown.config.mjs
File metadata and controls
68 lines (63 loc) · 1.76 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { builtinModules } from 'node:module'
import path from 'node:path'
import { defineConfig } from 'tsdown'
const { default: manifest } = await import(path.resolve('package.json'), {
with: { type: 'json' },
})
const dependencies = new Set([
...builtinModules,
...builtinModules.map(name => `node:${name}`),
...Object.keys(manifest.dependencies ?? {}),
...Object.keys(manifest.peerDependencies ?? {}),
...Object.keys(manifest.optionalDependencies ?? {}),
])
const neverBundle = id => {
const name = /^(@[^/]+\/[^/]+|[^/]+)/.exec(id)?.[1]
return dependencies.has(name)
}
const common = {
cwd: process.cwd(),
entry: { index: manifest.source },
tsconfig: 'tsconfig.lib.json',
target: 'esnext',
platform: 'neutral',
deps: { neverBundle, alwaysBundle: ['@algorithm.ts/internal'], onlyBundle: [] },
clean: true,
exports: false,
}
export default defineConfig([
...[
['esm', manifest.module],
['cjs', manifest.main],
].map(([format, file]) => ({
...common,
format,
outDir: path.dirname(file),
outExtensions: () => ({ js: path.extname(file) }),
sourcemap: process.env.BUILD_SOURCEMAP === 'true',
cjsDefault: false,
dts: false,
inputOptions: {
transform: { typescript: { optimizeConstEnums: true } },
},
outputOptions: {
exports: 'named',
comments: process.env.NODE_ENV !== 'production',
},
})),
{
...common,
format: 'esm',
outDir: path.dirname(manifest.types),
outExtensions: () => ({ dts: '.d.ts' }),
sourcemap: false,
// Keep non-exported helper types private in declaration files.
footer: { dts: 'export {};' },
dts: {
generator: 'tsgo',
emitDtsOnly: true,
sourcemap: false,
compilerOptions: { declarationMap: false },
},
},
])