Repository navigation
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
86 lines (73 loc) · 2.25 KB
/
Copy pathtsdown.config.ts
File metadata and controls
86 lines (73 loc) · 2.25 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// import path from 'node:path'
import { defineConfig } from 'tsdown/config'
export default defineConfig({
entry: ['./src/index.ts'],
outExtensions: (context) => {
if (context.format === 'es') {
return {
js: '.mjs',
dts: '.d.ts',
}
}
return { js: '.js', dts: '.d.ts' }
},
dts: {
resolve: true,
resolver: 'tsc',
build: true,
},
format: ['esm'],
shims: true,
target: 'node18',
platform: 'node',
sourcemap: false,
outDir: 'dist',
clean: true,
treeshake: true,
// 在开发模式下启用 用于分析打包体积
// outputOptions (outputOptions) {
// outputOptions.chunkFileNames = 'chunks/[name]-[hash].js'
// outputOptions.advancedChunks = {
// // 该选项的作用是指示打包工具是否递归地将模块的依赖包含在生成的 chunk 中。
// includeDependenciesRecursively: false,
// groups: [
// {
// // 按包名分组
// name (id) {
// console.log(id)
// if (id.includes('node_modules')) {
// const pkg = getPackageName(id)
// // /** 文件名称 不包含后缀 */
// const name = path.basename(id, path.extname(id))
// return `${pkg || 'vendor'}/${name}`
// }
// return null
// },
// // 匹配 node_modules 下所有模块
// test: /.*/,
// priority: 1,
// // 每个包最大 100KB,超过会拆成 2 个、1 个...
// maxSize: 100000,
// // 单模块也不能超过 100 KB
// maxModuleSize: 250000,
// },
// ],
// }
// return outputOptions
// },
})
// const getPackageName = (filePath: string): string | null => {
// // 格式化为绝对路径
// const absPath = path.resolve(filePath).replace(/\\/g, '/')
// const idx = absPath.lastIndexOf('node_modules/')
// if (idx === -1) return null
// const suffix = absPath.slice(idx + 13)
// const parts = suffix.split('/').filter(Boolean)
// if (parts.length === 0) return null
// // 组织包 (@scope/package)
// if (parts[0].startsWith('@')) {
// return parts.length > 1 ? `${parts[0]}/${parts[1]}` : null
// }
// // 普通包
// return parts[0]
// }