UNPKG

12.9 kBTypeScriptView Raw
1// Type definitions for webpack-dev-server 4.3
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// Alexey Pyltsyn <https://github.com/lex111>
15// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
16// TypeScript Version: 3.8
17
18import * as webpack from 'webpack';
19import * as httpProxyMiddleware from 'http-proxy-middleware';
20import * as express from 'express';
21import * as serveStatic from 'serve-static';
22import * as https from 'https';
23import * as http from 'http';
24import * as connectHistoryApiFallback from 'connect-history-api-fallback';
25import * as bonjour from 'bonjour';
26import * as webpackDevMiddleware from 'webpack-dev-middleware';
27import * as serveIndex from 'serve-index';
28import * as chokidar from 'chokidar';
29
30declare namespace WebpackDevServer {
31 interface Client {
32 /**
33 * Allows to set log level in the browser, e.g. before reloading,
34 * before an error or when Hot Module Replacement is enabled.
35 */
36 logging?: 'log' | 'info' | 'warn' | 'error' | 'none' | 'verbose' | undefined;
37 /**
38 * Shows a full-screen overlay in the browser when there are compiler
39 * errors or warnings. Disabled by default.
40 */
41 overlay?:
42 | boolean
43 | {
44 warnings?: boolean | undefined;
45 errors?: boolean | undefined;
46 }
47 | undefined;
48 /**
49 * Prints compilation progress in percentage in the browser.
50 */
51 progress?: boolean | undefined;
52 /**
53 * This option allows us either to choose the current web-socket server
54 * or to provide custom web-socket server implementation.
55 */
56 webSocketTransport?: 'ws' | 'sockjs' | string | undefined;
57 /**
58 * This option allows to specify URL to web socket server (useful when
59 * you're proxying dev server and client script does not always know
60 * where to connect to).
61 */
62 webSocketURL?: string | WebSocketURL | undefined;
63 }
64
65 type Header = Array<{ key: string; value: string }> | Record<string, string | string[]>;
66
67 interface Open {
68 /**
69 * Open specified browser.
70 */
71 app?: string | string[] | OpenApp | undefined;
72 /**
73 * Opens specified page in browser.
74 */
75 target?: string | string[] | undefined;
76 }
77
78 interface OpenApp {
79 arguments?: string[] | undefined;
80 name?: string | undefined;
81 }
82
83 interface ProxyConfigMap {
84 [url: string]: string | httpProxyMiddleware.Options;
85 }
86
87 type ProxyConfigArrayItem = {
88 path?: string | string[] | undefined;
89 context?: string | string[] | httpProxyMiddleware.Filter | undefined;
90 } & httpProxyMiddleware.Options;
91
92 type ProxyConfigArray = ProxyConfigArrayItem[];
93
94 interface Static {
95 /**
96 * Tell the server where to serve content from. This is only necessary
97 * if you want to serve static files. devServer.publicPath will be used
98 * to determine where the bundles should be served from, and takes
99 * precedence.
100 */
101 directory?: string | undefined;
102 /**
103 * Tell the server at which URL to serve static.directory content. For example to
104 * serve a file assets/manifest.json at /serve-public-path-url/manifest.json, your
105 * configurations should be as following:
106 */
107 publicPath?: string | string[] | undefined;
108 /**
109 * Tell dev-server to use serveIndex middleware when enabled.
110 *
111 * serveIndex middleware generates directory listings on viewing
112 * directories that don't have an index.html file.
113 */
114 serveIndex?: boolean | serveIndex.Options | undefined;
115 /**
116 * It is possible to configure advanced options for serving static files
117 * from static.directory. See the Express documentation for the possible
118 * options.
119 */
120 staticOptions?: serveStatic.ServeStaticOptions | undefined;
121 /**
122 * Tell dev-server to watch the files served by the static.directory
123 * option. It is disabled by default. When enabled, file changes will
124 * trigger a full page reload.
125 */
126 watch?: boolean | chokidar.WatchOptions | undefined;
127 }
128
129 interface WatchFiles {
130 options?: chokidar.WatchOptions | undefined;
131 paths?: string[] | string | undefined;
132 }
133
134 interface WebSocketURL {
135 /**
136 * Tells clients connected to devServer to use the provided hostname.
137 */
138 hostname?: string | undefined;
139 /**
140 * Tells clients connected to devServer to use the provided password to authenticate.
141 */
142 password?: string | undefined;
143 /**
144 * Tells clients connected to devServer to use the provided path to connect.
145 */
146 pathname?: string | undefined;
147 /**
148 * Tells clients connected to devServer to use the provided port.
149 */
150 port?: number | string | undefined;
151 /**
152 * Tells clients connected to devServer to use the provided protocol.
153 */
154 protocol?: string | undefined;
155 /**
156 * Tells clients connected to devServer to use the provided username to authenticate.
157 */
158 username?: string | undefined;
159 }
160
161 interface Configuration {
162 /**
163 * This option allows you to whitelist services that are allowed to
164 * access the dev server.
165 */
166 allowedHosts?: 'all' | string | string[] | undefined;
167 /**
168 * This option broadcasts the server via ZeroConf networking on start.
169 */
170 bonjour?: boolean | bonjour.BonjourOptions | undefined;
171 client?: Client | undefined;
172 /**
173 * Enable gzip compression for everything served.
174 */
175 compress?: boolean | undefined;
176 devMiddleware?: webpackDevMiddleware.Options;
177 /** Adds headers to all responses. */
178 headers?: Header | (() => Header) | undefined;
179 /**
180 * When using the HTML5 History API, the index.html page will likely
181 * have to be served in place of any 404 responses.
182 */
183 historyApiFallback?: boolean | connectHistoryApiFallback.Options | undefined;
184 /**
185 * Specify a host to use. By default this is localhost.
186 */
187 host?: 'local-ip' | 'local-ipv4' | 'local-ipv6' | string | undefined;
188 /**
189 * Enable webpack's Hot Module Replacement feature.
190 */
191 hot?: 'only' | boolean | undefined;
192 /**
193 * Serve over HTTP/2 using spdy. This option is ignored for Node 10.0.0
194 * and above, as spdy is broken for those versions. The dev server will
195 * migrate over to Node's built-in HTTP/2 once Express supports it.
196 */
197 http2?: boolean | undefined;
198 /**
199 * By default dev-server will be served over HTTP. It can optionally be
200 * served over HTTP/2 with HTTPS.
201 */
202 https?: boolean | https.ServerOptions | undefined;
203 /* The Unix socket to listen to (instead of a host). */
204 ipc?: boolean | string | undefined;
205 /**
206 * Tells dev-server whether to enable magic HTML routes (routes
207 * corresponding to your webpack output, for example '/main' for
208 * 'main.js').
209 * @default true
210 */
211 magicHtml?: boolean | undefined;
212 /**
213 * By default, the dev-server will reload/refresh the page when file
214 * changes are detected. devServer.hot option must be disabled or
215 * devServer.watchContentBase option must be enabled in order for
216 * liveReload to take effect. Disable devServer.liveReload by setting it
217 * to false
218 */
219 liveReload?: boolean | undefined;
220 /**
221 * Provides the ability to execute custom middleware after all other
222 * middleware internally within the server.
223 */
224 onAfterSetupMiddleware?: ((devServer: WebpackDevServer) => void) | undefined;
225 /**
226 * Provides the ability to execute custom middleware prior to all other
227 * middleware internally within the server.
228 */
229 onBeforeSetupMiddleware?: ((devServer: WebpackDevServer) => void) | undefined;
230 /**
231 * Provides an option to execute a custom function when
232 * webpack-dev-server starts listening for connections on a port.
233 */
234 onListening?: ((devServer: WebpackDevServer) => void) | undefined;
235 /** When open is enabled, the dev server will open the browser. */
236 open?: boolean | string | string[] | Open | Open[] | undefined;
237 /** Specify a port number to listen for requests on. */
238 port?: 'auto' | string | number | undefined;
239 /**
240 * Proxying some URLs can be useful when you have a separate API
241 * backend development server and you want to send API requests on the
242 * same domain.
243 *
244 * The dev-server makes use of the powerful http-proxy-middleware
245 * package. Check out its
246 * [documentation](https://github.com/chimurai/http-proxy-middleware#options)
247 * for more advanced usages. Note that some of http-proxy-middleware's
248 * features do not require a target key, e.g. its router feature, but
249 * you will still need to include a target key in your config here,
250 * otherwise webpack-dev-server won't pass it along to
251 * http-proxy-middleware).
252 */
253 proxy?: ProxyConfigMap | ProxyConfigArray | undefined;
254 /**
255 * Allows to close dev server and exit the process on SIGINT and SIGTERM
256 * signals.
257 */
258 setupExitSignals?: boolean | undefined;
259 /**
260 * This options allows to configure options for serving static files
261 * from directory (by default 'public' directory).
262 */
263 static?: boolean | string | Static | Array<string | Static> | undefined;
264 /**
265 * This option allows you to configure list of globs/directories/files
266 * to watch for file changes.
267 */
268 watchFiles?: string | string[] | WatchFiles | Array<WatchFiles | string> | undefined;
269 /**
270 * This option allows us either to choose the current web-socket server
271 * or to provide custom web-socket server implementation.
272 */
273 webSocketServer?: boolean | 'sockjs' | 'ws' | string | (() => void) | Record<string, any>;
274 }
275}
276
277declare module 'webpack' {
278 interface Configuration {
279 /**
280 * Can be used to configure the behaviour of webpack-dev-server when
281 * the webpack config is passed to webpack-dev-server CLI.
282 */
283 devServer?: WebpackDevServer.Configuration | undefined;
284 }
285}
286
287declare class WebpackDevServer {
288 app: express.Application;
289 server: http.Server;
290 sockets: NodeJS.EventEmitter[];
291
292 constructor(config: WebpackDevServer.Configuration, webpack?: webpack.Compiler | webpack.MultiCompiler);
293
294 /**
295 * @deprecated - use `options` as the first argument and `compiler` as the second argument.
296 */
297 constructor(webpack: webpack.Compiler | webpack.MultiCompiler, config?: WebpackDevServer.Configuration);
298
299 /**
300 * @deprecated - use `startCallback` or `start` instead
301 */
302 listen(port: number, hostname: string, callback?: (error?: Error) => void): http.Server;
303
304 /**
305 * @deprecated - use `startCallback` or `start` instead
306 */
307 listen(port: number, callback?: (error?: Error) => void): http.Server;
308
309 /**
310 * @deprecated - use `stopCallback` or `stop` instead
311 */
312 close(callback?: () => void): void;
313
314 /** @async */
315 start(): Promise<void>;
316
317 startCallback(callback: () => void): void;
318
319 /** @async */
320 stop(): Promise<void>;
321
322 stopCallback(callback: () => void): void;
323
324 sendMessage(sockets: NodeJS.EventEmitter[], type: string, data?: any): void;
325}
326
327export = WebpackDevServer;
328
\No newline at end of file