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