UNPKG

8.34 kBTypeScriptView Raw
1import { ModuleFormat as RollupFormat, InputOptions, OutputOptions, Plugin as RollupPlugin } from 'rollup';
2import { Banner } from './utils/get-banner';
3declare type Diff<T extends keyof any, U extends keyof any> = ({
4 [P in T]: P;
5} & {
6 [P in U]: never;
7} & {
8 [x: string]: never;
9})[T];
10declare type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U;
11export declare type Format = RollupFormat | 'cjs-min' | 'es-min' | 'esm-min' | 'umd-min' | 'iife-min' | 'amd-min' | 'system-min';
12export declare type Env = {
13 [k: string]: string | number | boolean;
14};
15export declare type External = string | RegExp | ((id: string, parentId?: string) => boolean);
16export declare type Externals = Array<External>;
17export declare type ConfigEntryObject = {
18 [entryName: string]: string;
19};
20export declare type ExtendConfig = (config: NormalizedConfig, { format, input }: {
21 format: Format;
22 input: string[] | ConfigEntryObject;
23}) => NormalizedConfig;
24export interface RunContext {
25 unresolved: Set<string>;
26}
27export interface Task {
28 title: string;
29 getConfig(context: RunContext, task: Task): Promise<RollupConfig>;
30}
31export interface RollupInputConfig extends InputOptions {
32 plugins: Array<RollupPlugin>;
33}
34export interface RollupOutputConfig extends OutputOptions {
35 dir: string;
36}
37export interface RollupConfig {
38 inputConfig: RollupInputConfig;
39 outputConfig: RollupOutputConfig;
40}
41export declare type ExtendRollupConfig = (config: RollupConfig) => RollupConfig;
42export interface FileNameContext {
43 format: RollupFormat;
44 minify: boolean;
45}
46export declare type GetFileName = (context: FileNameContext, defaultFileName: string) => string;
47export interface BabelPresetOptions {
48 /**
49 * Transform `async/await` to `Promise`.
50 * @default `true`
51 */
52 asyncToPromises?: boolean;
53 /**
54 * Custom JSX pragma. If you want to use Preact, set it to `h`.
55 */
56 jsx?: string;
57 /**
58 * Replace `Object.assign` with your own method.
59 * @example `myAssign`
60 */
61 objectAssign?: string;
62 /**
63 * Disable .babelrc
64 * By default Bili reads it
65 */
66 babelrc?: boolean;
67 /**
68 * Disable babel.config.js
69 */
70 configFile?: boolean;
71 /**
72 * Disable babel-preset-env but still use other babel plugins
73 * In addtional we use rollup-plugin-buble after rollup-plugin-babel
74 */
75 minimal?: boolean;
76}
77export declare type OutputTarget = 'node' | 'browser';
78export interface ConfigOutput {
79 /**
80 * Output format(s). You can append `min` to the format to generate minified bundle.
81 *
82 * @default `cjs`
83 * @cli `--format <format>`
84 */
85 format?: Format | Format[];
86 /**
87 * Output directory
88 * @default `dist`
89 * @cli `-d, --out-dir <dir>`
90 */
91 dir?: string;
92 /**
93 * Output file name
94 *
95 * Default value:
96 * - `[name][min][ext]` in `cjs` and `esm` format.
97 * - `[name][min].[format].js` in other formats.
98 *
99 * Placeholders:
100 * - `[name]`: The base name of input file. (without extension)
101 * - `[format]`: The output format. (without `-min` suffix)
102 * - `[min]`: It will replaced by `.min` when the format ends with `-min`, otherwise it's an empty string.
103 *
104 * The value can also be a function which returns the fileName template,
105 * The placeholders are also available in the return value.
106 *
107 * @cli `--file-name <fileName>`
108 */
109 fileName?: string | GetFileName;
110 /**
111 * Module name for umd bundle
112 */
113 moduleName?: string;
114 /**
115 * Whether to minify output files regardless of format, using this option won't add `.min` suffix to the output file name.
116 */
117 minify?: boolean;
118 /**
119 * Extract CSS into a single file.
120 * @default `true`
121 */
122 extractCSS?: boolean;
123 /**
124 * Generate source maps
125 * @default `true` for minified bundle, `false` otherwise
126 */
127 sourceMap?: boolean;
128 /**
129 * Exclude source code in source maps
130 */
131 sourceMapExcludeSources?: boolean;
132 /**
133 * Output target
134 * @default `node`
135 * @cli `--target <target>`
136 */
137 target?: OutputTarget;
138}
139export interface Config {
140 /**
141 * Input files
142 * @default `src/index.js`
143 * @cli `bili [...input]`
144 */
145 input?: string | ConfigEntryObject | Array<ConfigEntryObject | string>;
146 output?: ConfigOutput;
147 /**
148 * Define env variables that are only available in your library code. i.e. if you have some code like this in your library.
149 *
150 * ```js
151 * if (process.env.NODE_ENV === 'development') {
152 * console.log('debug')
153 * }
154 * ```
155 *
156 * And you can run following command to replace the env variable:
157
158 * ```bash
159 * bili --env.NODE_ENV production
160 * ```
161 *
162 * By default we don't add any env variables.
163 *
164 * @cli `--env.<name> value`
165 */
166 env?: Env;
167 /**
168 * Use Rollup plugins
169 *
170 * ```js
171 * // bili.config.js
172 * module.exports = {
173 * plugins: {
174 * svelte: {
175 * // Any options for rollup-plugin-svelte
176 * }
177 * }
178 * }
179 * ```
180 *
181 * You can also use CLI flags to add plugins, e.g.
182 * ```bash
183 * bili --plugin.svelte
184 * # with option
185 * bili --plugin.svelte.foo bar
186 * # Same as using `svelte: { foo: 'bar' }` in config file
187 * ```
188 *
189 * @cli `--plugin.<name> [option]`
190 */
191 plugins?: {
192 [name: string]: any;
193 };
194 /**
195 * Defines how to resolve a plugin by name
196 * This will override the default behavior
197 * e.g.
198 * ```js
199 * {
200 * resolvePlugins: {
201 * replace: require('./my-fork-of-rollup-plugin-replace')
202 * }
203 * }
204 * ```
205 */
206 resolvePlugins?: {
207 [name: string]: any;
208 };
209 /**
210 * Include node modules in the bundle. Note that this is always `true` for UMD bundle.
211 * @cli `--bundle-node-modules`
212 */
213 bundleNodeModules?: boolean | string[];
214 /**
215 * When inlining node modules
216 * You can use this option to exclude specific modules
217 */
218 externals?: Externals;
219 /**
220 * Specifies `moduleId: variableName` pairs necessary for external imports in umd/iife bundles. For example, in a case like this...
221 *
222 * ```js
223 * import $ from 'jquery'
224 * ```
225 *
226 * ...you can map the `jquery` module ID to the global `$` variable:
227 *
228 * ```js
229 * // bili.config.js
230 * export default {
231 * globals: {
232 * jquery: '$'
233 * }
234 * }
235 * ```
236 *
237 * @cli `--global.<moduleId> <variableName`
238 */
239 globals?: {
240 [k: string]: string;
241 };
242 /**
243 * Insert a copyright message to the top of output bundle.
244 */
245 banner?: Banner;
246 /**
247 * Configure the default babel preset
248 */
249 babel?: BabelPresetOptions;
250 /**
251 * Extending Bili config
252 */
253 extendConfig?: ExtendConfig;
254 /**
255 * Extending generated rollup config
256 */
257 extendRollupConfig?: ExtendRollupConfig;
258}
259interface ConfigOutputOverwrite {
260 /**
261 * Output directory, always a string
262 */
263 dir: string;
264}
265export interface NormalizedConfig {
266 input?: string | ConfigEntryObject | Array<ConfigEntryObject | string>;
267 output: Overwrite<ConfigOutput, ConfigOutputOverwrite>;
268 env?: Env;
269 bundleNodeModules?: boolean | string[];
270 plugins: {
271 [name: string]: any;
272 };
273 resolvePlugins?: {
274 [name: string]: any;
275 };
276 externals: Externals;
277 globals?: {
278 [k: string]: string;
279 };
280 banner?: Banner;
281 babel: BabelPresetOptions;
282 extendConfig?: ExtendConfig;
283 extendRollupConfig?: ExtendRollupConfig;
284}
285export interface Options {
286 /**
287 * Log level
288 */
289 logLevel?: 'verbose' | 'quiet';
290 /**
291 * Always show stack trace
292 */
293 stackTrace?: boolean;
294 /**
295 * Use a custom config file rather than auto-loading bili.config.js
296 */
297 configFile?: string | boolean;
298 /**
299 * The root directory to resolve files from
300 * Useful for mono-repo
301 * e.g. You can install Bili in root directory and leaf packages can use their own Bili config file:
302 * - `bili --root-dir packages/foo`
303 * - `bili --root-dir packages/bar`
304 */
305 rootDir?: string;
306}
307export {};