1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import { RawSourceMap } from 'source-map'
|
7 | import * as acorn from 'acorn'
|
8 |
|
9 | export type Format = 'amd' | 'cjs' | 'es' | 'iife' | 'umd'
|
10 |
|
11 | export interface SourceMap extends RawSourceMap {
|
12 | toString(): string
|
13 | toUrl(): string
|
14 | }
|
15 |
|
16 |
|
17 | export interface Warning {
|
18 | code: string
|
19 | message: string
|
20 | loc?: { file: string, line: number, column: number }
|
21 | frame?: string
|
22 | }
|
23 |
|
24 | export interface BundleOptions {
|
25 |
|
26 | format?: Format
|
27 |
|
28 | exports?: 'auto' | 'default' | 'named' | 'none'
|
29 |
|
30 | moduleId?: string
|
31 |
|
32 | moduleName?: string
|
33 |
|
34 | globals?: { [id: string]: string }
|
35 | |
36 |
|
37 |
|
38 |
|
39 | indent?: string | boolean
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 | interop?: boolean
|
46 |
|
47 | banner?: string
|
48 |
|
49 | footer?: string
|
50 |
|
51 | intro?: string
|
52 |
|
53 | outro?: string
|
54 | |
55 |
|
56 |
|
57 |
|
58 | useStrict?: boolean
|
59 | }
|
60 |
|
61 | export interface GenerateOptions extends BundleOptions {
|
62 |
|
63 | sourceMap?: boolean
|
64 | |
65 |
|
66 |
|
67 |
|
68 | sourceMapFile?: string
|
69 | }
|
70 |
|
71 | export interface WriteOptions extends BundleOptions {
|
72 |
|
73 | dest: string
|
74 |
|
75 | sourceMap?: boolean | 'inline'
|
76 |
|
77 | sourceMapFile?: string
|
78 | }
|
79 |
|
80 | export interface Bundle {
|
81 |
|
82 | generate(options: GenerateOptions): { code: string, map: SourceMap }
|
83 |
|
84 | write(options: WriteOptions): Promise<void>
|
85 | }
|
86 |
|
87 | export interface Options {
|
88 |
|
89 | entry: string
|
90 |
|
91 | cache?: Bundle
|
92 | |
93 |
|
94 |
|
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 module – i.e., the value of `this` at the top level – is `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
|
122 | export 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 */
|
154 | export function rollup(options: Options): Promise<Bundle>
|
155 |
|
\ | No newline at end of file |