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