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