UNPKG

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