-
-
Notifications
You must be signed in to change notification settings - Fork 228
/
options.ts
242 lines (230 loc) · 5.83 KB
/
options.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import type { BuildOptions, Plugin as EsbuildPlugin, Loader } from 'esbuild'
import type { InputOption } from 'rollup'
import { MarkRequired } from 'ts-essentials'
import type { Plugin } from './plugin'
import type { TreeshakingStrategy } from './plugins/tree-shaking'
import type { MinifyOptions } from 'terser'
export type KILL_SIGNAL = 'SIGKILL' | 'SIGTERM'
export type Format = 'cjs' | 'esm' | 'iife'
export type ContextForOutPathGeneration = {
options: NormalizedOptions
format: Format
/** "type" field in project's package.json */
pkgType?: string
}
export type OutExtensionObject = { js?: string; dts?: string }
export type OutExtensionFactory = (
ctx: ContextForOutPathGeneration
) => OutExtensionObject
export type DtsConfig = {
entry?: InputOption
/** Resolve external types used in dts files from node_modules */
resolve?: boolean | (string | RegExp)[]
/** Emit declaration files only */
only?: boolean
/** Insert at the top of each output .d.ts file */
banner?: string
/** Insert at the bottom */
footer?: string
/**
* Overrides `compilerOptions`
* This option takes higher priority than `compilerOptions` in tsconfig.json
*/
compilerOptions?: any
}
export type BannerOrFooter =
| {
js?: string
css?: string
}
| ((ctx: { format: Format }) => { js?: string; css?: string } | undefined)
export type BrowserTarget =
| 'chrome'
| 'deno'
| 'edge'
| 'firefox'
| 'hermes'
| 'ie'
| 'ios'
| 'node'
| 'opera'
| 'rhino'
| 'safari'
export type BrowserTargetWithVersion =
| `${BrowserTarget}${number}`
| `${BrowserTarget}${number}.${number}`
| `${BrowserTarget}${number}.${number}.${number}`
export type EsTarget =
| 'es3'
| 'es5'
| 'es6'
| 'es2015'
| 'es2016'
| 'es2017'
| 'es2018'
| 'es2019'
| 'es2020'
| 'es2021'
| 'es2022'
| 'esnext'
export type Target = BrowserTarget | BrowserTargetWithVersion | EsTarget
export type Entry = string[] | Record<string, string>
/**
* The options available in tsup.config.ts
* Not all of them are available from CLI flags
*/
export type Options = {
/** Optional config name to show in CLI output */
name?: string
/**
* @deprecated Use `entry` instead
*/
entryPoints?: Entry
entry?: Entry
/**
* Output different formats to different folder instead of using different extensions
*/
legacyOutput?: boolean
/**
* Compile target
*
* default to `node16`
*/
target?: Target | Target[]
minify?: boolean | 'terser'
terserOptions?: MinifyOptions
minifyWhitespace?: boolean
minifyIdentifiers?: boolean
minifySyntax?: boolean
keepNames?: boolean
watch?: boolean | string | (string | boolean)[]
ignoreWatch?: string[] | string
onSuccess?:
| string
| (() => Promise<void | undefined | (() => void | Promise<void>)>)
jsxFactory?: string
jsxFragment?: string
outDir?: string
outExtension?: OutExtensionFactory
format?: Format[] | Format
globalName?: string
env?: {
[k: string]: string
}
define?: {
[k: string]: string
}
dts?: boolean | string | DtsConfig
sourcemap?: boolean | 'inline'
/** Always bundle modules matching given patterns */
noExternal?: (string | RegExp)[]
/** Don't bundle these modules */
external?: (string | RegExp)[]
/**
* Replace `process.env.NODE_ENV` with `production` or `development`
* `production` when the bundled is minified, `development` otherwise
*/
replaceNodeEnv?: boolean
/**
* Code splitting
* Default to `true`
* You may want to disable code splitting sometimes: [`#255`](https://github.com/egoist/tsup/issues/255)
*/
splitting?: boolean
/**
* Clean output directory before each build
*/
clean?: boolean | string[]
esbuildPlugins?: EsbuildPlugin[]
esbuildOptions?: (options: BuildOptions, context: { format: Format }) => void
/**
* Suppress non-error logs (excluding "onSuccess" process output)
*/
silent?: boolean
/**
* Skip node_modules bundling
* Will still bundle modules matching the `noExternal` option
*/
skipNodeModulesBundle?: boolean
/**
* @see https://esbuild.github.io/api/#pure
*/
pure?: string | string[]
/**
* Disable bundling, default to true
*/
bundle?: boolean
/**
* This option allows you to automatically replace a global variable with an import from another file.
* @see https://esbuild.github.io/api/#inject
*/
inject?: string[]
/**
* Emit esbuild metafile
* @see https://esbuild.github.io/api/#metafile
*/
metafile?: boolean
footer?: BannerOrFooter
banner?: BannerOrFooter
/**
* Target platform
* @default `node`
*/
platform?: 'node' | 'browser' | 'neutral'
/**
* Esbuild loader option
*/
loader?: Record<string, Loader>
/**
* Disable config file with `false`
* Or pass a custom config filename
*/
config?: boolean | string
/**
* Use a custom tsconfig
*/
tsconfig?: string
/**
* Inject CSS as style tags to document head
* @default {false}
*/
injectStyle?: boolean | ((css: string, fileId: string) => string)
/**
* Inject cjs and esm shims if needed
* @default false
*/
shims?: boolean
/**
* TSUP plugins
* @experimental
* @alpha
*/
plugins?: Plugin[]
/**
* By default esbuild already does treeshaking
*
* But this option allow you to perform additional treeshaking with Rollup
*
* This can result in smaller bundle size
*/
treeshake?: TreeshakingStrategy
/**
* Copy the files inside `publicDir` to output directory
*/
publicDir?: string | boolean
killSignal?: KILL_SIGNAL
/**
* Interop default within `module.exports` in cjs
* @default false
*/
cjsInterop?: boolean
}
export type NormalizedOptions = Omit<
MarkRequired<Options, 'entry' | 'outDir'>,
'dts' | 'format'
> & {
dts?: DtsConfig
tsconfigResolvePaths: Record<string, string[]>
tsconfigDecoratorMetadata?: boolean
format: Format[]
}