UNPKG

10.7 kBTypeScriptView Raw
1// Type definitions for webpack-dev-server 3.4
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// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
12// TypeScript Version: 2.3
13
14import * as webpack from 'webpack';
15import * as httpProxyMiddleware from 'http-proxy-middleware';
16import * as express from 'express';
17import * as serveStatic from 'serve-static';
18import * as https from 'https';
19import * as http from 'http';
20import * as connectHistoryApiFallback from 'connect-history-api-fallback';
21
22declare namespace WebpackDevServer {
23 interface ListeningApp {
24 address(): { port?: number };
25 }
26
27 interface ProxyConfigMap {
28 [url: string]: string | httpProxyMiddleware.Config;
29 }
30
31 type ProxyConfigArrayItem = {
32 path?: string | string[];
33 context?: string | string[] | httpProxyMiddleware.Filter;
34 } & httpProxyMiddleware.Config;
35
36 type ProxyConfigArray = ProxyConfigArrayItem[];
37
38 interface Configuration {
39 /** Provides the ability to execute custom middleware after all other middleware internally within the server. */
40 after?: (app: express.Application, server: WebpackDevServer, compiler: webpack.Compiler) => void;
41 /** This option allows you to whitelist services that are allowed to access the dev server. */
42 allowedHosts?: string[];
43 /** Provides the ability to execute custom middleware prior to all other middleware internally within the server. */
44 before?: (app: express.Application, server: WebpackDevServer, compiler: webpack.Compiler) => void;
45 /** This option broadcasts the server via ZeroConf networking on start. */
46 bonjour?: boolean;
47 /**
48 * When using inline mode, the console in your DevTools will show you messages e.g. before reloading,
49 * before an error or when Hot Module Replacement is enabled. This may be too verbose.
50 */
51 clientLogLevel?: 'none' | 'error' | 'warning' | 'info';
52 /** Enable gzip compression for everything served. */
53 compress?: boolean;
54 /**
55 * Tell the server where to serve content from. This is only necessary if you want to serve static files.
56 * devServer.publicPath will be used to determine where the bundles should be served from, and takes precedence.
57 */
58 contentBase?: boolean | string | string[];
59 /**
60 * When set to true this option bypasses host checking.
61 * THIS IS NOT RECOMMENDED as apps that do not check the host are vulnerable to DNS rebinding attacks.
62 */
63 disableHostCheck?: boolean;
64 /**
65 * This option lets you reduce the compilations in lazy mode.
66 * By default in lazy mode, every request results in a new compilation.
67 * With filename, it's possible to only compile when a certain file is requested.
68 */
69 filename?: string;
70 /** Adds headers to all responses. */
71 headers?: {
72 [key: string]: string;
73 };
74 /** When using the HTML5 History API, the index.html page will likely have to be served in place of any 404 responses. */
75 historyApiFallback?: boolean | connectHistoryApiFallback.Options;
76 /** Specify a host to use. By default this is localhost. */
77 host?: string;
78 /** Enable webpack's Hot Module Replacement feature. */
79 hot?: boolean;
80 /** Enables Hot Module Replacement (see devServer.hot) without page refresh as fallback in case of build failures. */
81 hotOnly?: boolean;
82 /**
83 * Serve over HTTP/2 using spdy. This option is ignored for Node 10.0.0 and above,
84 * as spdy is broken for those versions. The dev server will migrate over to Node's
85 * built-in HTTP/2 once Express supports it.
86 */
87 http2?: boolean;
88 /** By default dev-server will be served over HTTP. It can optionally be served over HTTP/2 with HTTPS. */
89 https?: boolean | https.ServerOptions;
90 /** The filename that is considered the index file. */
91 index?: string;
92 /**
93 * Tells devServer to inject a client. Setting devServer.injectClient to true will result
94 * in always injecting a client. It is possible to provide a function to inject conditionally
95 */
96 injectClient?: boolean | ((compilerConfig: webpack.Compiler) => boolean);
97 /**
98 * Tells devServer to inject a Hot Module Replacement. Setting devServer.injectHot
99 * to true will result in always injecting. It is possible to provide a function to
100 * inject conditionally
101 */
102 injectHot?: boolean | ((compilerConfig: webpack.Compiler) => boolean);
103 /**
104 * Toggle between the dev-server's two different modes.
105 * By default the application will be served with inline mode enabled.
106 * This means that a script will be inserted in your bundle to take care of live reloading,
107 * and build messages will appear in the browser console.
108 */
109 inline?: boolean;
110 /**
111 * When lazy is enabled, the dev-server will only compile the bundle when it gets requested.
112 * This means that webpack will not watch any file changes.
113 */
114 lazy?: boolean;
115 /**
116 * By default, the dev-server will reload/refresh the page when file changes are detected.
117 */
118 liveReload?: boolean;
119 /**
120 * Allows dev-server to register custom mime types.
121 */
122 mimeTypes?:
123 | {
124 [key: string]: string[];
125 }
126 | {
127 typeMap?: {
128 [key: string]: string[];
129 } & {
130 force: boolean;
131 };
132 };
133 /**
134 * With noInfo enabled, messages like the webpack bundle information that is shown
135 * when starting up and after each save,will be hidden.
136 * Errors and warnings will still be shown.
137 */
138 noInfo?: boolean;
139 /** When open is enabled, the dev server will open the browser. */
140 open?: boolean;
141 /** Specify a page to navigate to when opening the browser. */
142 openPage?: string;
143 /** Shows a full-screen overlay in the browser when there are compiler errors or warnings. Disabled by default. */
144 overlay?:
145 | boolean
146 | {
147 warnings?: boolean;
148 errors?: boolean;
149 };
150 /** When used via the CLI, a path to an SSL .pfx file. If used in options, it should be the bytestream of the .pfx file. */
151 pfx?: string;
152 /** The passphrase to a SSL PFX file. */
153 pfxPassphrase?: string;
154 /** Specify a port number to listen for requests on. */
155 port?: number;
156 /**
157 * Proxying some URLs can be useful when you have a separate API backend development server
158 * and you want to send API requests on the same domain.
159 */
160 proxy?: ProxyConfigMap | ProxyConfigArray;
161 /**
162 * When using inline mode and you're proxying dev-server,
163 * the inline client script does not always know where to connect to.
164 * It will try to guess the URL of the server based on window.location, but if that fails you'll need to use this.
165 */
166 public?: string;
167 /** The bundled files will be available in the browser under this path. */
168 publicPath?: string;
169 /**
170 * With quiet enabled, nothing except the initial startup information will be written to the console.
171 * This also means that errors or warnings from webpack are not visible.
172 */
173 quiet?: boolean;
174 /**
175 * Tells dev-server to use serveIndex middleware when enabled.
176 */
177 serveIndex?: boolean;
178 /** @deprecated Here you can access the Express app object and add your own custom middleware to it. */
179 setup?: (app: express.Application, server: WebpackDevServer) => void;
180 /** The Unix socket to listen to (instead of a host). */
181 socket?: string;
182 /**
183 * Tells clients connected to devServer to use provided socket host.
184 */
185 sockHost?: string;
186 /** The path at which to connect to the reloading socket. */
187 sockPath?: string;
188 /** It is possible to configure advanced options for serving static files from contentBase. */
189 staticOptions?: serveStatic.ServeStaticOptions;
190 /**
191 * This option lets you precisely control what bundle information gets displayed.
192 * This can be a nice middle ground if you want some bundle information, but not all of it.
193 */
194 stats?: webpack.Options.Stats;
195 /** This option lets the browser open with your local IP. */
196 useLocalIp?: boolean;
197 /** Tell the server to watch the files served by the devServer.contentBase option. File changes will trigger a full page reload. */
198 watchContentBase?: boolean;
199 /** Control options related to watching the files. */
200 watchOptions?: webpack.WatchOptions;
201 /** Tells devServer to write generated assets to the disk. */
202 writeToDisk?: boolean | ((filePath: string) => boolean);
203 }
204}
205
206declare module 'webpack' {
207 interface Configuration {
208 /** Can be used to configure the behaviour of webpack-dev-server when the webpack config is passed to webpack-dev-server CLI. */
209 devServer?: WebpackDevServer.Configuration;
210 }
211}
212
213declare class WebpackDevServer {
214 constructor(webpack: webpack.Compiler | webpack.MultiCompiler, config?: WebpackDevServer.Configuration);
215
216 static addDevServerEntrypoints(
217 webpackOptions: webpack.Configuration | webpack.Configuration[],
218 config: WebpackDevServer.Configuration,
219 listeningApp?: WebpackDevServer.ListeningApp,
220 ): void;
221
222 listen(port: number, hostname: string, callback?: (error?: Error) => void): http.Server;
223
224 listen(port: number, callback?: (error?: Error) => void): http.Server;
225
226 close(callback?: () => void): void;
227}
228
229export = WebpackDevServer;
230
\No newline at end of file