-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
113 lines (95 loc) · 2.32 KB
/
Copy pathtsdown.config.ts
File metadata and controls
113 lines (95 loc) · 2.32 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import type { PackageIndexes, PackageManifest } from '@vueuse/metadata'
import type { Format, UserConfig } from 'tsdown'
import { globSync } from 'tinyglobby'
import { StaleGuardRecorder } from 'tsdown-stale-guard'
import metadata from './packages/metadata/index.json' with { type: 'json' }
const functions = metadata.functions as PackageIndexes['functions']
const externals = [
'vue',
/@vueuse\/.*/,
]
export function createTsDownConfig(
pkg: PackageManifest,
copy?: UserConfig['copy'],
cwd = process.cwd(),
) {
const { globals, external, submodules, iife, build, mjs, dts, target = 'es2018' } = pkg
if (build === false)
return []
const iifeName = 'VueUse'
const iifeGlobals = {
'vue': 'Vue',
'@vueuse/shared': 'VueUse',
'@vueuse/core': 'VueUse',
...(globals || {}),
}
const format: Format[] = []
if (mjs !== false) {
format.push('es')
}
const baseConfig: UserConfig = {
target,
dts,
platform: 'browser',
deps: {
neverBundle: [
...externals,
...(external || []),
],
},
}
const configs: UserConfig[] = []
const functionNames = ['index']
if (submodules) {
functionNames.push(...globSync(
'*/index.ts',
{ cwd },
).map(i => i.split('/')[0]))
}
const entry: Record<string, string> = {}
for (const fn of functionNames) {
const fnEntry = {
[fn]: fn === 'index' ? 'index.ts' : `${fn}/index.ts`,
}
if (iife !== false) {
const BASE_IIFE_CONFIG: UserConfig = {
...baseConfig,
entry: fnEntry,
format: 'iife',
globalName: iifeName,
outputOptions: {
extend: true,
globals: iifeGlobals,
},
}
configs.push(
BASE_IIFE_CONFIG,
{
...BASE_IIFE_CONFIG,
minify: true,
outExtensions: () => ({
js: '.min.js',
}),
},
)
}
Object.assign(entry, fnEntry)
const info = functions.find(i => i.name === fn)
if (info?.component) {
Object.assign(entry, { [`${fn}/component`]: `${fn}/component.ts` })
}
}
configs.push({
...baseConfig,
entry,
format,
copy,
plugins: [StaleGuardRecorder()],
attw: {
level: 'error',
profile: 'esm-only',
ignoreRules: ['cjs-resolves-to-esm'],
},
})
return configs
}