UNPKG

6.58 kBTypeScriptView Raw
1// Type definitions for parcel-bundler 1.12
2// Project: https://github.com/parcel-bundler/parcel#readme
3// Definitions by: pinage404 <https://github.com/pinage404>
4// Ceci Woodward <https://github.com/ceci-woodward>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6// TypeScript Version: 2.3
7
8import * as http from 'http';
9import * as https from 'https';
10import * as express from "express-serve-static-core";
11
12declare namespace ParcelBundler {
13 interface HttpsOptions {
14 /**
15 * Path to custom certificate
16 *
17 * @default "./ssl/c.crt"
18 */
19 cert?: string | undefined;
20 /**
21 * Path to custom key
22 *
23 * @default "./ssl/k.key"
24 */
25 key?: string | undefined;
26 }
27
28 interface ParcelOptions {
29 /**
30 * The out directory to put the build files in
31 *
32 * @default "./dist"
33 */
34 outDir?: string | undefined;
35 /**
36 * The name of the outputFile
37 *
38 * @default "index.html"
39 */
40 outFile?: string | undefined;
41 /**
42 * The url to server on
43 *
44 * @default "./"
45 */
46 publicUrl?: string | undefined;
47 /**
48 * Whether to watch the files and rebuild them on change
49 *
50 * @default process.env.NODE_ENV !== 'production'
51 */
52 watch?: boolean | undefined;
53 /**
54 * Enabled or disables caching
55 *
56 * @default true
57 */
58 cache?: boolean | undefined;
59 /**
60 * The directory cache gets put in
61 *
62 * @default ".cache"
63 */
64 cacheDir?: string | undefined;
65 /**
66 * Disable content hash from being included on the filename
67 *
68 * @default false
69 */
70 contentHash?: boolean | undefined;
71 /**
72 * Minify files
73 *
74 * @default process.env.NODE_ENV === 'production'
75 */
76 minify?: boolean | undefined;
77 /**
78 * Turn on experimental scope hoisting/tree shaking flag, for smaller production bundles
79 *
80 * @default false
81 */
82 scopeHoist?: boolean | undefined;
83 /**
84 * @default "browser"
85 */
86 target?: "browser" | "node" | "electron" | undefined;
87 /**
88 * Define a custom {key, cert} pair
89 *
90 * Use true to generate one or false to use http
91 */
92 https?:
93 | true
94 | false
95 | HttpsOptions | undefined;
96 /**
97 * 3 = log everything, 2 = log warnings & errors, 1 = log errors
98 *
99 * @default 3
100 */
101 logLevel?: 3 | 2 | 1 | undefined;
102 /**
103 * The port the HMR socket runs on
104 *
105 * Defaults to a random free port (0 in node.js resolves to a random free port)
106 *
107 * @default 0
108 */
109 hmrPort?: 0 | number | undefined;
110 /**
111 * Enable or disable sourcemaps
112 *
113 * Defaults to enabled (not supported in minified builds yet)
114 *
115 * @default true
116 */
117 sourceMaps?: boolean | undefined;
118 /**
119 * A hostname for hot module reload
120 *
121 * @default ""
122 */
123 hmrHostname?: string | undefined;
124 /**
125 * Prints a detailed report of the bundles, assets, filesizes and times
126 *
127 * Reports are only printed if watch is disabled
128 *
129 * @default false
130 */
131 detailedReport?: boolean | undefined;
132
133 /**
134 * Expose modules as UMD under this name, disabled by default
135 */
136 global?: string | undefined;
137
138 /**
139 * By default, package.json dependencies are not included when using 'node' or 'electron' with the 'target' option.
140 *
141 * Set to true to add them to the bundle.
142 *
143 * @default false
144 */
145 bundleNodeModules?: true | false | undefined;
146
147 /**
148 * Enable or disable HMR while watching
149 *
150 * @default false
151 */
152 hmr?: true | false | undefined;
153
154 /**
155 * Enable or disable auto install of missing dependencies found during bundling
156 *
157 * @default true
158 */
159 autoInstall?: boolean | undefined;
160 }
161
162 type ParcelAsset = any;
163
164 interface ParcelBundle {
165 /**
166 * The type of assets it contains (e.g. js, css, map, ...)
167 */
168 type: string;
169 /**
170 * The name of the bundle (generated using Asset.generateBundleName() of entryAsset)
171 */
172 name: string;
173 /**
174 * The parent bundle, is null in case of the entry bundleany
175 */
176 parentBundle?: any;
177 /**
178 * The entryPoint of the bundle, used for generating the name and gathering assets.
179 */
180 entryAsset: any;
181 /**
182 * A Set of all assets inside the bundle
183 */
184 assets: Set<any>;
185 /**
186 * A Set of all sibling bundles
187 */
188 siblingBundles: Set<any>;
189 /**
190 * A Map<String(Type: js, css, map, ...), Bundle> of all sibling bundles
191 */
192 siblingBundlesMap: Map<string, ParcelBundle>;
193 /**
194 * A Map<Asset, number(line number inside the bundle)> of all the locations of the assets inside the bundle, used to generate accurate source maps
195 */
196 offsets: Map<ParcelAsset, number>;
197
198 /**
199 * A Set of all child bundles
200 */
201 childBundles: Set<any>;
202 }
203}
204
205declare class ParcelBundler {
206 constructor(
207 entryFiles?: string | string[],
208 options?: ParcelBundler.ParcelOptions
209 );
210
211 addAssetType(extension: string, path: string): void;
212
213 addPackager(type: string, packager: string): void;
214
215 bundle(): Promise<ParcelBundler.ParcelBundle>;
216
217 middleware(): (req: express.Request, res: express.Response, next: express.NextFunction) => any;
218
219 serve(port?: number, https?: true | false | ParcelBundler.HttpsOptions, host?: string): Promise<http.Server | https.Server>;
220
221 on(name: 'buildEnd', cb: () => void): void;
222 on(name: 'bundled', cb: (bundle: ParcelBundler.ParcelBundle) => void): void;
223 on(name: 'buildStart', cb: (entryPoints: string[]) => void): void;
224 on(name: 'buildError', cb: (error: Error) => void): void;
225
226 off(name: 'buildEnd'| 'bundled'| 'buildStart'| 'buildError', cb: (...any: any[]) => void): void;
227}
228
229export = ParcelBundler;