UNPKG

7.5 kBTypeScriptView Raw
1// Type definitions for rollup 0.41
2// Project: https://github.com/rollup/rollup
3// Definitions by: Philipp A. <https://github.com/flying-sheep>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6import { RawSourceMap } from 'source-map'
7import * as acorn from 'acorn'
8
9export type Format = 'amd' | 'cjs' | 'es' | 'iife' | 'umd'
10
11export interface SourceMap extends RawSourceMap {
12 toString(): string
13 toUrl(): string
14}
15
16// https://github.com/rollup/rollup/wiki/JavaScript-API
17export interface Warning {
18 code: string
19 message: string
20 loc?: { file: string, line: number, column: number }
21 frame?: string
22}
23
24export interface BundleOptions {
25 /** The format of the generated bundle. */
26 format?: Format
27 /** What export mode to use. Defaults to auto, which guesses your intentions based on what the `entry` module exports. */
28 exports?: 'auto' | 'default' | 'named' | 'none'
29 /** An ID to use for AMD/UMD bundles. */
30 moduleId?: string
31 /** The name to use for the module for UMD/IIFE bundles (required for bundles with exports). */
32 moduleName?: string
33 /** Mapping of IDs → global variable names. Used for UMD/IIFE bundles. */
34 globals?: { [id: string]: string }
35 /**
36 * The indent string to use, for formats that require code to be indented (AMD, IIFE, UMD).
37 * Can also be false (no indent), or true (the default – auto-indent)
38 */
39 indent?: string | boolean
40 /**
41 * Whether or not to add an 'interop block'. By default (interop: true).
42 * For safety's sake, Rollup will assign any external dependencies' default exports to a separate variable if it's necessary to distinguish between default and named exports.
43 * This generally only applies if your external dependencies were transpiled (for example with Babel) – if you're sure you don't need it, you can save a few bytes with interop: false.
44 */
45 interop?: boolean
46 /** A string to prepend to the bundle. */
47 banner?: string
48 /** A string to append to the bundle. */
49 footer?: string
50 /** A string prepended to the code inside of the format-specific wrapper */
51 intro?: string
52 /** A string appended to the code inside of the format-specific wrapper */
53 outro?: string
54 /**
55 * Whether to include the 'use strict' pragma at the top of generated non-ES6 bundles.
56 * Strictly-speaking (geddit?), ES6 modules are always in strict mode, so you shouldn't disable this without good reason.
57 */
58 useStrict?: boolean
59}
60
61export interface GenerateOptions extends BundleOptions {
62 /** Whether to generate a sourcemap. If true, the return value from `bundle.generate(...)` will include a map property */
63 sourceMap?: boolean
64 /**
65 * The location of the generated bundle. If this is an absolute path, all the sources paths in the sourcemap will be relative to it.
66 * The map.file property is the basename of sourceMapFile, as the location of the sourcemap is assumed to be adjacent to the bundle.
67 */
68 sourceMapFile?: string
69}
70
71export interface WriteOptions extends BundleOptions {
72 /** The file to write to. If `options.sourceMap === true`, two files will be created – `dest` and `dest + '.map`. */
73 dest: string
74 /** If `true`, a separate sourcemap file will be created. If `'inline'`, the sourcemap will be appended to the resulting dest file as a data URI. */
75 sourceMap?: boolean | 'inline'
76 /** This option is unnecessary, as it defaults to the value of dest. */
77 sourceMapFile?: string
78}
79
80export interface Bundle {
81 /** Generate bundled code as an object */
82 generate(options: GenerateOptions): { code: string, map: SourceMap }
83 /** writes the file (and accompanying sourcemap file, if appropriate) to the file system. */
84 write(options: WriteOptions): Promise<void>
85}
86
87export interface Options {
88 /** The bundle's entry point (e.g. your `main.js` or `app.js` or `index.js`) */
89 entry: string
90 /** A previous bundle. Use it to speed up subsequent bundles :) */
91 cache?: Bundle
92 /**
93 * Function that returns if an ID is external or array of IDs of modules that should remain external to the bundle.
94 * The IDs should be either the name of an external dependency or a resolved ID (like an absolute path to a file)
95 */
96 external?: ((id: string) => boolean) | string[]
97 /**
98 * Function that takes an ID and returns a path, or Object of id: path pairs.
99 * Where supplied, these paths will be used in the generated bundle instead of the module ID, allowing you to (for example) load dependencies from a CDN.
100 */
101 paths?: ((id: string) => string) | { [id: string]: string }
102 /** Function that will intercept warning messages. If not supplied, warnings will be deduplicated and printed to the console. */
103 onwarn?(warning: Warning): void
104 /** Array of plugin objects or a single plugin object */
105 plugins?: Plugin | Plugin[]
106 /**
107 * Whether or not to apply tree-shaking. (Default: true)
108 * It's recommended that you omit this option, unless you discover a bug caused by the tree-shaking algorithm in which case use treeshake: false once you've filed an issue!
109 */
110 treeshake?: boolean
111 /** Any options that should be passed through to Acorn. */
112 acorn?: acorn.Options
113 /** By default, the context of a modulei.e., the value of `this` at the top levelis `undefined`. In rare cases you might need to change this to something else, like `'window'`. */
114 context?: any
115 /** Same as `options.context`, but per-module. */
116 moduleContext?: ((id: string) => any) | { [id: string]: any }
117 /** Adds support for very old environments like IE8, at the cost of some extra code. */
118 legacy?: boolean
119}
120
121// https://github.com/rollup/rollup/wiki/Plugins#creating-plugins
122export interface Plugin {
123 /** The name of the plugin, for use in error messages and warnings */
124 name?: string
125 /** A function that replaces or manipulates the options object passed to rollup.rollup */
126 options?(options: Options): Options
127 /** A custom loader. Returning null or undefined defers to other load functions (and eventually the default behavior of loading from the file system). */
128 load?(id: string): string | null | undefined
129 /**
130 * Custom resolver (useful for e.g. locating third-party dependencies).
131 * Returning null or undefined defers to other resolveId functions (and eventually the default resolution behavior);
132 * returning any other falsy value signals that importee should be treated as an external module and not included in the bundle.
133 */
134 resolveId?(importee: string, importer: string): string | null | undefined | false | 0 | ''
135 /** A module transformer function */
136 transform?(source: string, id: string): string | { code: string, map: SourceMap }
137 /** A bundle transformer function */
138 transformBundle?(source: string, options: { format: Format }): string | { code: string, map: SourceMap }
139 /** Function hook called when bundle.generate() is being executed. */
140 ongenerate?(options: GenerateOptions, bundle: Bundle): void
141 /** Function hook called when bundle.write() is being executed, after the file has been written to disk. */
142 onwrite?(options: WriteOptions, bundle: Bundle): void
143 /** A function for generating intro text */
144 intro?(): string
145 /** A function for generating outro text */
146 outro?(): string
147 /** Prepend to the bundle. */
148 banner?: string | (() => string)
149 /** Apppend to the bundle. */
150 footer?: string | (() => string)
151}
152
153/** Returns a Promise that resolves with a bundle */
154export function rollup(options: Options): Promise<Bundle>
155
\No newline at end of file