1 | /// <reference types="node" />
|
2 |
|
3 | import insertGlobals = require("insert-module-globals");
|
4 |
|
5 | declare var browserify: browserify.BrowserifyConstructor;
|
6 | export = browserify;
|
7 |
|
8 | declare namespace browserify {
|
9 | /**
|
10 | * Options pertaining to an individual file.
|
11 | */
|
12 | interface FileOptions {
|
13 | // If true, this is considered an entry point to your app.
|
14 | entry?: boolean | undefined;
|
15 | // Expose this file under a custom dependency name.
|
16 | // require('./vendor/angular/angular.js', {expose: 'angular'}) enables require('angular')
|
17 | expose?: string | undefined;
|
18 | // Basedir to use to resolve this file's path.
|
19 | basedir?: string | undefined;
|
20 | // The name/path to the file.
|
21 | file?: string | undefined;
|
22 | // Forward file to external() to be externalized.
|
23 | external?: boolean | undefined;
|
24 | // Disable transforms on file if set to false.
|
25 | transform?: boolean | undefined;
|
26 | // The ID to use for require() statements.
|
27 | id?: string | undefined;
|
28 | }
|
29 |
|
30 | // Browserify accepts a filename, an input stream for file inputs, or a FileOptions configuration
|
31 | // for each file in a bundle.
|
32 | type InputFile = string | NodeJS.ReadableStream | FileOptions;
|
33 |
|
34 | /**
|
35 | * Core options pertaining to a Browserify instance, extended by user options
|
36 | */
|
37 | interface CustomOptions {
|
38 | /**
|
39 | * Custom properties can be defined on Options.
|
40 | * These options are forwarded along to module-deps and browser-pack directly.
|
41 | */
|
42 | [propName: string]: any;
|
43 | /** the directory that Browserify starts bundling from for filenames that start with .. */
|
44 | basedir?: string | undefined;
|
45 | }
|
46 | /**
|
47 | * Options pertaining to a Browserify instance.
|
48 | */
|
49 | interface Options extends CustomOptions {
|
50 | // String, file object, or array of those types (they may be mixed) specifying entry file(s).
|
51 | entries?: InputFile | InputFile[] | undefined;
|
52 | // an array which will skip all require() and global parsing for each file in the array.
|
53 | // Use this for giant libs like jquery or threejs that don't have any requires or node-style globals but take forever to parse.
|
54 | noParse?: string[] | undefined;
|
55 | // an array of optional extra extensions for the module lookup machinery to use when the extension has not been specified.
|
56 | // By default Browserify considers only .js and .json files in such cases.
|
57 | extensions?: string[] | undefined;
|
58 | // an array of directories that Browserify searches when looking for modules which are not referenced using relative path.
|
59 | // Can be absolute or relative to basedir. Equivalent of setting NODE_PATH environmental variable when calling Browserify command.
|
60 | paths?: string[] | undefined;
|
61 | // sets the algorithm used to parse out the common paths. Use false to turn this off, otherwise it uses the commondir module.
|
62 | commondir?: boolean | undefined;
|
63 | // disables converting module ids into numerical indexes. This is useful for preserving the original paths that a bundle was generated with.
|
64 | fullPaths?: boolean | undefined;
|
65 | // sets the list of built-ins to use, which by default is set in lib/builtins.js in this distribution.
|
66 | builtins?: string[] | { [builtinName: string]: string } | boolean | undefined;
|
67 | // set if external modules should be bundled. Defaults to true.
|
68 | bundleExternal?: boolean | undefined;
|
69 | // When true, always insert process, global, __filename, and __dirname without analyzing the AST for faster builds but larger output bundles. Default false.
|
70 | insertGlobals?: boolean | undefined;
|
71 | // When true, scan all files for process, global, __filename, and __dirname, defining as necessary.
|
72 | // With this option npm modules are more likely to work but bundling takes longer. Default true.
|
73 | detectGlobals?: boolean | undefined;
|
74 | // When true, add a source map inline to the end of the bundle. This makes debugging easier because you can see all the original files if you are in a modern enough browser.
|
75 | debug?: boolean | undefined;
|
76 | // When a non-empty string, a standalone module is created with that name and a umd wrapper.
|
77 | // You can use namespaces in the standalone global export using a . in the string name as a separator, for example 'A.B.C'.
|
78 | // The global export will be sanitized and camel cased.
|
79 | standalone?: string | undefined;
|
80 | // will be passed to insert-module-globals as the opts.vars parameter.
|
81 | insertGlobalVars?: insertGlobals.VarsOption | undefined;
|
82 | // defaults to 'require' in expose mode but you can use another name.
|
83 | externalRequireName?: string | undefined;
|
84 | }
|
85 |
|
86 | interface BrowserifyConstructor {
|
87 | (files: InputFile[], opts?: Options): BrowserifyObject;
|
88 | (file: InputFile, opts?: Options): BrowserifyObject;
|
89 | (opts?: Options): BrowserifyObject;
|
90 | new(files: InputFile[], opts?: Options): BrowserifyObject;
|
91 | new(file: InputFile, opts?: Options): BrowserifyObject;
|
92 | new(opts?: Options): BrowserifyObject;
|
93 | }
|
94 |
|
95 | interface BrowserifyObject extends NodeJS.EventEmitter {
|
96 | /**
|
97 | * Add an entry file from file that will be executed when the bundle loads.
|
98 | * If file is an array, each item in file will be added as an entry file.
|
99 | */
|
100 | add(file: InputFile | InputFile[], opts?: FileOptions): BrowserifyObject;
|
101 | /**
|
102 | * Make file available from outside the bundle with require(file).
|
103 | * The file param is anything that can be resolved by require.resolve().
|
104 | * file can also be a stream, but you should also use opts.basedir so that relative requires will be resolvable.
|
105 | * If file is an array, each item in file will be required. In file array form, you can use a string or object for each item. Object items should have a file property and the rest of the parameters will be used for the opts.
|
106 | * Use the expose property of opts to specify a custom dependency name. require('./vendor/angular/angular.js', {expose: 'angular'}) enables require('angular')
|
107 | */
|
108 | require(file: InputFile, opts?: FileOptions): BrowserifyObject;
|
109 | /**
|
110 | * Bundle the files and their dependencies into a single javascript file.
|
111 | * Return a readable stream with the javascript file contents or optionally specify a cb(err, buf) to get the buffered results.
|
112 | */
|
113 | bundle(cb?: (err: any, src: Buffer) => any): NodeJS.ReadableStream;
|
114 | /**
|
115 | * Prevent file from being loaded into the current bundle, instead referencing from another bundle.
|
116 | * If file is an array, each item in file will be externalized.
|
117 | * If file is another bundle, that bundle's contents will be read and excluded from the current bundle as the bundle in file gets bundled.
|
118 | */
|
119 | external(file: string[], opts?: CustomOptions): BrowserifyObject;
|
120 | external(file: string, opts?: CustomOptions): BrowserifyObject;
|
121 | external(file: BrowserifyObject): BrowserifyObject;
|
122 | /**
|
123 | * Prevent the module name or file at file from showing up in the output bundle.
|
124 | * Instead you will get a file with module.exports = {}.
|
125 | */
|
126 | ignore(file: string, opts?: CustomOptions): BrowserifyObject;
|
127 | /**
|
128 | * Prevent the module name or file at file from showing up in the output bundle.
|
129 | * If your code tries to require() that file it will throw unless you've provided another mechanism for loading it.
|
130 | */
|
131 | exclude(file: string, opts?: CustomOptions): BrowserifyObject;
|
132 | /**
|
133 | * Transform source code before parsing it for require() calls with the transform function or module name tr.
|
134 | * If tr is a function, it will be called with tr(file) and it should return a through-stream that takes the raw file contents and produces the transformed source.
|
135 | * If tr is a string, it should be a module name or file path of a transform module
|
136 | */
|
137 | transform<T extends CustomOptions>(tr: string, opts?: T): BrowserifyObject;
|
138 | transform<T extends CustomOptions>(
|
139 | tr: (file: string, opts: T) => NodeJS.ReadWriteStream,
|
140 | opts?: T,
|
141 | ): BrowserifyObject;
|
142 | /**
|
143 | * Register a plugin with opts. Plugins can be a string module name or a function the same as transforms.
|
144 | * plugin(b, opts) is called with the Browserify instance b.
|
145 | */
|
146 | plugin<T extends CustomOptions>(plugin: string, opts?: T): BrowserifyObject;
|
147 | plugin<T extends CustomOptions>(plugin: (b: BrowserifyObject, opts: T) => any, opts?: T): BrowserifyObject;
|
148 | /**
|
149 | * Reset the pipeline back to a normal state. This function is called automatically when bundle() is called multiple times.
|
150 | * This function triggers a 'reset' event.
|
151 | */
|
152 | reset(opts?: Options): void;
|
153 |
|
154 | /**
|
155 | * When a file is resolved for the bundle, the bundle emits a 'file' event with the full file path, the id string passed to require(), and the parent object used by browser-resolve.
|
156 | * You could use the file event to implement a file watcher to regenerate bundles when files change.
|
157 | */
|
158 | on(event: "file", listener: (file: string, id: string, parent: any) => any): this;
|
159 | /**
|
160 | * When a package.json file is read, this event fires with the contents.
|
161 | * The package directory is available at pkg.__dirname.
|
162 | */
|
163 | on(event: "package", listener: (pkg: any) => any): this;
|
164 | /**
|
165 | * When .bundle() is called, this event fires with the bundle output stream.
|
166 | */
|
167 | on(event: "bundle", listener: (bundle: NodeJS.ReadableStream) => any): this;
|
168 | /**
|
169 | * When the .reset() method is called or implicitly called by another call to .bundle(), this event fires.
|
170 | */
|
171 | on(event: "reset", listener: () => any): this;
|
172 | /**
|
173 | * When a transform is applied to a file, the 'transform' event fires on the bundle stream with the transform stream tr and the file that the transform is being applied to.
|
174 | */
|
175 | on(event: "transform", listener: (tr: NodeJS.ReadWriteStream, file: string) => any): this;
|
176 | on(event: string, listener: Function): this;
|
177 |
|
178 | /**
|
179 | * Set to any until substack/labeled-stream-splicer is defined
|
180 | */
|
181 | pipeline: any;
|
182 | }
|
183 | }
|
184 |
|
\ | No newline at end of file |