1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | import * as webpack from 'webpack';
|
19 | import * as httpProxyMiddleware from 'http-proxy-middleware';
|
20 | import * as express from 'express';
|
21 | import * as serveStatic from 'serve-static';
|
22 | import * as https from 'https';
|
23 | import * as http from 'http';
|
24 | import * as connectHistoryApiFallback from 'connect-history-api-fallback';
|
25 | import * as bonjour from 'bonjour';
|
26 | import * as webpackDevMiddleware from 'webpack-dev-middleware';
|
27 | import * as serveIndex from 'serve-index';
|
28 | import * as chokidar from 'chokidar';
|
29 |
|
30 | declare namespace WebpackDevServer {
|
31 | interface Client {
|
32 | |
33 |
|
34 |
|
35 |
|
36 | logging?: 'log' | 'info' | 'warn' | 'error' | 'none' | 'verbose' | undefined;
|
37 | |
38 |
|
39 |
|
40 |
|
41 | overlay?:
|
42 | | boolean
|
43 | | {
|
44 | warnings?: boolean | undefined;
|
45 | errors?: boolean | undefined;
|
46 | }
|
47 | | undefined;
|
48 | |
49 |
|
50 |
|
51 | progress?: boolean | undefined;
|
52 | |
53 |
|
54 |
|
55 |
|
56 | webSocketTransport?: 'ws' | 'sockjs' | string | undefined;
|
57 | |
58 |
|
59 |
|
60 |
|
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 |
|
70 |
|
71 | app?: string | string[] | OpenApp | undefined;
|
72 | |
73 |
|
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 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | directory?: string | undefined;
|
102 | |
103 |
|
104 |
|
105 |
|
106 |
|
107 | publicPath?: string | string[] | undefined;
|
108 | |
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | serveIndex?: boolean | serveIndex.Options | undefined;
|
115 | |
116 |
|
117 |
|
118 |
|
119 |
|
120 | staticOptions?: serveStatic.ServeStaticOptions | undefined;
|
121 | |
122 |
|
123 |
|
124 |
|
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 |
|
137 |
|
138 | hostname?: string | undefined;
|
139 | |
140 |
|
141 |
|
142 | password?: string | undefined;
|
143 | |
144 |
|
145 |
|
146 | pathname?: string | undefined;
|
147 | |
148 |
|
149 |
|
150 | port?: number | string | undefined;
|
151 | |
152 |
|
153 |
|
154 | protocol?: string | undefined;
|
155 | |
156 |
|
157 |
|
158 | username?: string | undefined;
|
159 | }
|
160 |
|
161 | interface Configuration {
|
162 | |
163 |
|
164 |
|
165 |
|
166 | allowedHosts?: 'all' | string | string[] | undefined;
|
167 | |
168 |
|
169 |
|
170 | bonjour?: boolean | bonjour.BonjourOptions | undefined;
|
171 | client?: Client | undefined;
|
172 | |
173 |
|
174 |
|
175 | compress?: boolean | undefined;
|
176 | devMiddleware?: webpackDevMiddleware.Options;
|
177 |
|
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:
|
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 |
|
277 | declare 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 |
|
287 | declare 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 |
|
327 | export = WebpackDevServer;
|
328 |
|
\ | No newline at end of file |