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// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TypeScript Version: 2.3
6
7import * as express from "express-serve-static-core";
8import * as http from "http";
9import * as https from "https";
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
95 | 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(
220 port?: number,
221 https?: true | false | ParcelBundler.HttpsOptions,
222 host?: string,
223 ): Promise<http.Server | https.Server>;
224
225 on(name: "buildEnd", cb: () => void): void;
226 on(name: "bundled", cb: (bundle: ParcelBundler.ParcelBundle) => void): void;
227 on(name: "buildStart", cb: (entryPoints: string[]) => void): void;
228 on(name: "buildError", cb: (error: Error) => void): void;
229
230 off(name: "buildEnd" | "bundled" | "buildStart" | "buildError", cb: (...any: any[]) => void): void;
231}
232
233export = ParcelBundler;