This repository has been archived by the owner on Aug 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
interface.ts
204 lines (179 loc) · 6.82 KB
/
interface.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
import type { RollupOptions, ExternalOption, GlobalsOption, OutputOptions } from 'rollup'
import type { RollupNodeResolveOptions } from '@rollup/plugin-node-resolve'
import type { RollupCommonJSOptions } from '@rollup/plugin-commonjs'
import type { RollupTypescriptOptions } from '@rollup/plugin-typescript'
import type { RollupAliasOptions } from '@rollup/plugin-alias'
import type { RollupReplaceOptions } from '@rollup/plugin-replace'
import type { RollupJsonOptions } from '@rollup/plugin-json'
import type { RollupEslintOptions } from '@rollup/plugin-eslint'
import type { PostCSSPluginConf } from 'rollup-plugin-postcss'
import type { TypescriptPluginOptions } from 'rollup-plugin-ts'
import type { Options as RollupTerserOptions } from 'rollup-plugin-terser'
import type { PluginVisualizerOptions } from 'rollup-plugin-visualizer'
import type { TargetModuleType, ParserType } from './constant'
/**
* Type helper to make it easier to use libundler.config.ts
* accepts a direct {@link LibundlerConfig} object, or a function that returns {@link RollupOptions}.
*/
export function defineConfig(config: LibundlerConfigObject): LibundlerConfigObject
export function defineConfig(config: LibundlerConfigArray): LibundlerConfigArray
export function defineConfig(config: LibundlerConfigFn): LibundlerConfigFn
export function defineConfig(config: any) {
return config
}
export type LibundlerConfig = LibundlerConfigObject | LibundlerConfigArray | LibundlerConfigFn
export type LibundlerConfigFn = (defaultRollupOptions: Partial<RollupOptions>) => RollupOptions
export type LibundlerConfigArray = Array<LibundlerConfigObject>
export interface LibundlerConfigObject {
/**
* Library name.
* @default auto pascalify by `<package.json>.name`
* @example 'JsMusicPlayer'
*/
libName: string
/**
* Entry file path.
* @default 'src/index.js'
*/
entry?: string
/**
* Output bundle file dir.
* @default 'dist'
*/
outDir?: string
/**
* Output bundle file name.
* @default auto kebab-case by `<package.json>.name`
* @example 'js-music-player'
*/
outFileName?: string
/**
* File header of output bundle file, `false` to disable.
* @see [banner template](https://github.com/surmon-china/libundler/blob/main/src/banner.ts)
* @default <banner template>
*/
banner?: false | string
/**
* Generate sourcemap, `false` to disable.
* @see [banner template](https://rollupjs.org/guide/en/#outputsourcemap)
* @default true
*/
sourcemap?: OutputOptions['sourcemap']
/**
* Output bundle module types.
* @type `TargetBundleModuleType`
* @default ['umd', 'esm', 'cjs']
*/
targets?: TargetModuleType[]
/**
* Bundle file export mode.
* @type `OutputOptions.exports`
* @see [rollup - output.preserveModules](https://rollupjs.org/guide/en/#outputpreservemodules)
* @default 'auto'
*/
exports?: OutputOptions['exports']
/**
* Locate and bundle third-party dependencies in `node_modules`, `@rollup/plugin-node-resolve` options.
* @see [@rollup/plugin-node-resolve](https://github.com/rollup/plugins/tree/master/packages/node-resolve)
* @default {}
*/
nodeResolve?: false | RollupNodeResolveOptions
/**
* Define which locates modules, `@rollup/plugin-commonjs` options.
* @see [@rollup/plugin-commonjs](https://github.com/rollup/plugins/tree/master/packages/commonjs)
* @default {}
*/
commonjs?: RollupCommonJSOptions
/**
* Define and resolve aliases for bundle dependencies, `@rollup/plugin-alias` options.
* @see [@rollup/plugin-alias](https://github.com/rollup/plugins/tree/master/packages/alias)
* @default {}
*/
alias?: false | RollupAliasOptions
/**
* Replace strings in files while bundling, `@rollup/plugin-replace` options.
* @see [@rollup/plugin-replace](https://github.com/rollup/plugins/tree/master/packages/replace)
* @default
* {
* preventAssignment: true,
* 'PACKAGE_VERSION': <package.json>.version,
* 'process.env.NODE_ENV': '"production"'
* }
*/
replace?: RollupReplaceOptions
/**
* Treating `[module]` as external dependency.
* @see [rollup - peer-dependencies](https://rollupjs.org/guide/en/#peer-dependencies)
* @see [rollup - warning-treating-module-as-external-dependency](https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency)
* @default []
*/
external?: ExternalOption
/**
* Provide global variable names to replace your external imports.
* @see [rollup - output-globals](https://rollupjs.org/guide/en/#outputglobals)
* @default {}
*/
globals?: GlobalsOption
/**
* Rollup parser type. `false` to disable.
* @type `false` | `'babel'` | `'buble'`
* @default 'buble'
*/
parser?: false | ParserType
/**
* Rollup parser plugin options.
* @type `@rollup/plugin-babel` options | `@rollup/plugin-buble` options
* @see
* - [@rollup/plugin-babel](https://github.com/rollup/plugins/tree/master/packages/babel)
* - [@rollup/plugin-buble](https://github.com/rollup/plugins/tree/master/packages/buble)
* @default {}
*/
parserOptions?: Record<string, unknown>
/**
* Rollup postcss plugin options, defined to overwrite the default options.
* @see [rollup-plugin-postcss](https://github.com/egoist/rollup-plugin-postcss)
* @default {}
*/
postcss?: Partial<PostCSSPluginConf>
/**
* Rollup JSON plugin options, defined to overwrite the default options.
* @see [@rollup/plugin-json](https://github.com/rollup/plugins/tree/master/packages/json)
* @default {}
*/
json?: RollupJsonOptions
/**
* Rollup TypeScript plugin options, `false` to disable.
* @see [@rollup/plugin-typescript](https://github.com/rollup/plugins/tree/master/packages/typescript)
* @default false
*/
typescript?: false | Partial<RollupTypescriptOptions>
/**
* Enable TS plugin (before build), `false` to disable.
* @see [rollup-plugin-ts](https://github.com/wessberg/rollup-plugin-ts)
* @default auto enable by `<package.json>.devDependencies`
*/
ts?: false | Partial<TypescriptPluginOptions>
/**
* Enable ESLint plugin (before build), `false` to disable.
* @see [@rollup/plugin-eslint](https://github.com/rollup/plugins/tree/master/packages/eslint)
* @default auto enable by `<package.json>.devDependencies`
*/
eslint?: false | RollupEslintOptions
/**
* Enable compression, use terser, `false` to disable.
* @see [rollup-plugin-terser](https://github.com/TrySound/rollup-plugin-terser)
* @default true
*/
terser?: boolean | RollupTerserOptions
/**
* Visualize and analyze this bundle file, use `rollup-plugin-visualizer`, `false` to disable.
* @see [rollup-plugin-visualizer](https://github.com/btd/rollup-plugin-visualizer)
* @default false
*/
visualizer?: boolean | PluginVisualizerOptions
/**
* Display the rollup config info, `true` to enable.
* @default false
*/
verbose?: boolean
}