UNPKG

16.2 kBTypeScriptView Raw
1// Type definitions for webpack-dev-server 3.11
2// Project: https://github.com/webpack/webpack-dev-server
3// Definitions by: maestroh <https://github.com/maestroh>
4// Dave Parslow <https://github.com/daveparslow>
5// Zheyang Song <https://github.com/ZheyangSong>
6// Alan Agius <https://github.com/alan-agius4>
7// Artur Androsovych <https://github.com/arturovt>
8// Dave Cardwell <https://github.com/davecardwell>
9// Katsuya Hino <https://github.com/dobogo>
10// Billy Le <https://github.com/billy-le>
11// Chris Paterson <https://github.com/chrispaterson>
12// Piotr Błażejewicz <https://github.com/peterblazejewicz>
13// William Artero <https://github.com/wwmoraes>
14// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
15// TypeScript Version: 3.8
16
17import * as webpack from 'webpack';
18import * as httpProxyMiddleware from 'http-proxy-middleware';
19import * as express from 'express';
20import * as serveStatic from 'serve-static';
21import * as https from 'https';
22import * as http from 'http';
23import * as connectHistoryApiFallback from 'connect-history-api-fallback';
24
25declare namespace WebpackDevServer {
26 interface ListeningApp {
27 address(): { port?: number | undefined };
28 }
29
30 interface ProxyConfigMap {
31 [url: string]: string | httpProxyMiddleware.Options;
32 }
33
34 type ProxyConfigArrayItem = {
35 path?: string | string[] | undefined;
36 context?: string | string[] | httpProxyMiddleware.Filter | undefined;
37 } & httpProxyMiddleware.Options;
38
39 type ProxyConfigArray = ProxyConfigArrayItem[];
40
41 interface Configuration {
42 /**
43 * Provides the ability to execute custom middleware after all other
44 * middleware internally within the server.
45 */
46 after?: ((app: express.Application, server: WebpackDevServer, compiler: webpack.Compiler) => void) | undefined;
47 /**
48 * This option allows you to whitelist services that are allowed to
49 * access the dev server.
50 */
51 allowedHosts?: string[] | undefined;
52 /**
53 * Provides the ability to execute custom middleware prior to all
54 * other middleware internally within the server.
55 */
56 before?: ((app: express.Application, server: WebpackDevServer, compiler: webpack.Compiler) => void) | undefined;
57 /**
58 * This option broadcasts the server via ZeroConf networking on start.
59 */
60 bonjour?: boolean | undefined;
61 /**
62 * When using inline mode, the console in your DevTools will show you
63 * messages e.g. before reloading, before an error or when Hot Module
64 * Replacement is enabled. This may be too verbose.
65 *
66 * 'none' and 'warning' are going to be deprecated at the next major
67 * version.
68 */
69 clientLogLevel?: 'silent' | 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'none' | 'warning' | undefined;
70 /**
71 * Enable gzip compression for everything served.
72 */
73 compress?: boolean | undefined;
74 /**
75 * Tell the server where to serve content from. This is only necessary
76 * if you want to serve static files. devServer.publicPath will be used
77 * to determine where the bundles should be served from, and takes
78 * precedence.
79 */
80 contentBase?: boolean | string | string[] | number | undefined;
81 /**
82 * Tell the server at what URL to serve `devServer.contentBase`.
83 * If there was a file `assets/manifest.json`,
84 * it would be served at `/serve-content-base-at-this-url/manifest.json`
85 */
86 contentBasePublicPath?: string | string[] | undefined;
87 /**
88 * When set to true this option bypasses host checking. THIS IS NOT
89 * RECOMMENDED as apps that do not check the host are vulnerable to DNS
90 * rebinding attacks.
91 */
92 disableHostCheck?: boolean | undefined;
93 /**
94 * This option lets you reduce the compilations in lazy mode.
95 * By default in lazy mode, every request results in a new compilation.
96 * With filename, it's possible to only compile when a certain file is requested.
97 */
98 filename?: string | undefined;
99 /** Adds headers to all responses. */
100 headers?: {
101 [key: string]: string;
102 } | undefined;
103 /**
104 * When using the HTML5 History API, the index.html page will likely
105 * have to be served in place of any 404 responses.
106 */
107 historyApiFallback?: boolean | connectHistoryApiFallback.Options | undefined;
108 /**
109 * Specify a host to use. By default this is localhost.
110 */
111 host?: string | undefined;
112 /**
113 * Enable webpack's Hot Module Replacement feature.
114 * Note that webpack.HotModuleReplacementPlugin is required to fully
115 * enable HMR. If webpack or webpack-dev-server are launched with the
116 * --hot option, this plugin will be added automatically, so you may
117 * not need to add this to your webpack.config.js.
118 */
119 hot?: boolean | undefined;
120 /**
121 * Enables Hot Module Replacement (see devServer.hot) without page
122 * refresh as fallback in case of build failures.
123 */
124 hotOnly?: boolean | undefined;
125 /**
126 * Serve over HTTP/2 using spdy. This option is ignored for Node 10.0.0
127 * and above, as spdy is broken for those versions. The dev server will
128 * migrate over to Node's built-in HTTP/2 once Express supports it.
129 */
130 http2?: boolean | undefined;
131 /**
132 * By default dev-server will be served over HTTP. It can optionally be
133 * served over HTTP/2 with HTTPS.
134 */
135 https?: boolean | https.ServerOptions | undefined;
136 /**
137 * The filename that is considered the index file.
138 */
139 index?: string | undefined;
140 /**
141 * Tells devServer to inject a client. Setting devServer.injectClient
142 * to true will result in always injecting a client. It is possible to
143 * provide a function to inject conditionally
144 */
145 injectClient?: boolean | ((compilerConfig: webpack.Compiler) => boolean) | undefined;
146 /**
147 * Tells devServer to inject a Hot Module Replacement. Setting
148 * devServer.injectHot to true will result in always injecting. It is
149 * possible to provide a function to inject conditionally
150 */
151 injectHot?: boolean | ((compilerConfig: webpack.Compiler) => boolean) | undefined;
152 /**
153 * Toggle between the dev-server's two different modes. By default the
154 * application will be served with inline mode enabled. This means
155 * that a script will be inserted in your bundle to take care of live
156 * reloading, and build messages will appear in the browser console.
157 */
158 inline?: boolean | undefined;
159 /**
160 * When lazy is enabled, the dev-server will only compile the bundle
161 * when it gets requested. This means that webpack will not watch any
162 * file changes.
163 */
164 lazy?: boolean | undefined;
165 /**
166 * By default, the dev-server will reload/refresh the page when file
167 * changes are detected. devServer.hot option must be disabled or
168 * devServer.watchContentBase option must be enabled in order for
169 * liveReload to take effect. Disable devServer.liveReload by setting
170 * it to false
171 */
172 liveReload?: boolean | undefined;
173 /**
174 * The object is passed to the underlying webpack-dev-middleware. See
175 * [documentation](https://github.com/webpack/webpack-dev-middleware#mimetypes)
176 * for usage notes.
177 */
178 mimeTypes?:
179 | {
180 [key: string]: string[];
181 }
182 | {
183 typeMap?: {
184 [key: string]: string[];
185 } & {
186 force: boolean;
187 } | undefined;
188 } | undefined;
189 /**
190 * With noInfo enabled, messages like the webpack bundle information
191 * that is shown when starting up and after each save,will be hidden.
192 * Errors and warnings will still be shown.
193 */
194 noInfo?: boolean | undefined;
195 /**
196 * Provides an option to execute a custom function when
197 * webpack-dev-server starts listening for connections on a port.
198 */
199 onListening?: ((server: WebpackDevServer) => void) | undefined;
200 /** When open is enabled, the dev server will open the browser. */
201 open?: boolean | string | object | undefined;
202 /** Specify a page to navigate to when opening the browser. */
203 openPage?: string | string[] | undefined;
204 /**
205 * Shows a full-screen overlay in the browser when there are compiler
206 * errors or warnings. Disabled by default.
207 */
208 overlay?:
209 | boolean
210 | {
211 warnings?: boolean | undefined;
212 errors?: boolean | undefined;
213 } | undefined;
214 /**
215 * When used via the CLI, a path to an SSL .pfx file. If used in
216 * options, it should be the bytestream of the .pfx file.
217 */
218 pfx?: string | undefined;
219 /** The passphrase to a SSL PFX file. */
220 pfxPassphrase?: string | undefined;
221 /** Specify a port number to listen for requests on. */
222 port?: number | undefined;
223 /**
224 * Proxying some URLs can be useful when you have a separate API
225 * backend development server and you want to send API requests on the
226 * same domain.
227 *
228 * The dev-server makes use of the powerful http-proxy-middleware
229 * package. Check out its
230 * [documentation](https://github.com/chimurai/http-proxy-middleware#options)
231 * for more advanced usages. Note that some of http-proxy-middleware's
232 * features do not require a target key, e.g. its router feature, but
233 * you will still need to include a target key in your config here,
234 * otherwise webpack-dev-server won't pass it along to
235 * http-proxy-middleware).
236 */
237 proxy?: ProxyConfigMap | ProxyConfigArray | undefined;
238 /**
239 * When using inline mode and you're proxying dev-server, the inline
240 * client script does not always know where to connect to. It will try
241 * to guess the URL of the server based on window.location, but if that
242 * fails you'll need to use this.
243 */
244 public?: string | undefined;
245 /**
246 * The bundled files will be available in the browser under this path.
247 * default is '/'
248 */
249 publicPath?: string | undefined;
250 /**
251 * With quiet enabled, nothing except the initial startup information
252 * will be written to the console. This also means that errors or
253 * warnings from webpack are not visible.
254 */
255 quiet?: boolean | undefined;
256 /**
257 * Tells dev-server to use serveIndex middleware when enabled.
258 *
259 * serveIndex middleware generates directory listings on viewing
260 * directories that don't have an index.html file.
261 */
262 serveIndex?: boolean | undefined;
263 /**
264 * @deprecated This option is deprecated in favor of devServer.before
265 * and will be removed in v3.0.0. Here you can access the Express app
266 * object and add your own custom middleware to it.
267 */
268 setup?: ((app: express.Application, server: WebpackDevServer) => void) | undefined;
269 /** The Unix socket to listen to (instead of a host). */
270 socket?: string | undefined;
271 /**
272 * Tells clients connected to devServer to use provided socket host.
273 */
274 sockHost?: string | undefined;
275 /**
276 * The path at which to connect to the reloading socket. Default is
277 * '/sockjs-node'
278 */
279 sockPath?: string | undefined;
280 /**
281 * Tells clients connected to devServer to use provided socket port.
282 */
283 sockPort?: string | number | undefined;
284 /**
285 * It is possible to configure advanced options for serving static
286 * files from contentBase.
287 *
288 * This only works when using devServer.contentBase as a string.
289 */
290 staticOptions?: serveStatic.ServeStaticOptions | undefined;
291 /**
292 * This option lets you precisely control what bundle information gets
293 * displayed. This can be a nice middle ground if you want some bundle
294 * information, but not all of it.
295 */
296 stats?: webpack.Configuration['stats'] | undefined;
297 /**
298 * transportMode is an experimental option, meaning its usage could
299 * potentially change without warning.
300 *
301 * Providing a string to devServer.transportMode is a shortcut to
302 * setting both devServer.transportMode.client and
303 * devServer.transportMode.server to the given string value.
304 *
305 * This option allows us either to choose the current devServer
306 * transport mode for client/server individually or to provide custom
307 * client/server implementation. This allows to specify how browser or
308 * other client communicates with the devServer.
309 *
310 * The current default mode is 'sockjs'. This mode uses SockJS-node as
311 * a server, and SockJS-client on the client.
312 *
313 * 'ws' mode will become the default mode in the next major devServer
314 * version. This mode uses ws as a server, and native WebSockets on the
315 * client.
316 */
317 transportMode?:
318 | 'sockjs'
319 | 'ws'
320 | {
321 client: object;
322 server: 'ws';
323 }
324 | {
325 client: 'ws';
326 server: object;
327 }
328 | {
329 client: object;
330 server: object;
331 } | undefined;
332 /** This option lets the browser open with your local IP. */
333 useLocalIp?: boolean | undefined;
334 /**
335 * Tell the server to watch the files served by the
336 * devServer.contentBase option. File changes will trigger a full page
337 * reload.
338 */
339 watchContentBase?: boolean | undefined;
340 /** Control options related to watching the files. */
341 watchOptions?: webpack.Configuration['watchOptions'] | undefined;
342 /** Tells devServer to write generated assets to the disk. */
343 writeToDisk?: boolean | ((filePath: string) => boolean) | undefined;
344 }
345}
346
347declare module 'webpack' {
348 interface Configuration {
349 /**
350 * Can be used to configure the behaviour of webpack-dev-server when
351 * the webpack config is passed to webpack-dev-server CLI.
352 */
353 devServer?: WebpackDevServer.Configuration | undefined;
354 }
355}
356
357declare class WebpackDevServer {
358 listeningApp: WebpackDevServer.ListeningApp;
359 sockets: NodeJS.EventEmitter[];
360
361 constructor(webpack: webpack.Compiler | webpack.MultiCompiler, config?: WebpackDevServer.Configuration);
362
363 static addDevServerEntrypoints(
364 webpackOptions: webpack.Configuration | webpack.Configuration[],
365 config: WebpackDevServer.Configuration,
366 listeningApp?: WebpackDevServer.ListeningApp,
367 ): void;
368
369 listen(port: number, hostname: string, callback?: (error?: Error) => void): http.Server;
370
371 listen(port: number, callback?: (error?: Error) => void): http.Server;
372
373 close(callback?: () => void): void;
374
375 sockWrite(sockets: NodeJS.EventEmitter[], type: string, data?: any): void;
376}
377
378export = WebpackDevServer;
379
\No newline at end of file