UNPKG

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