diff --git a/types/webpack-dev-server/index.d.ts b/types/webpack-dev-server/index.d.ts index 0e76c3acce..a06ec04c5e 100644 --- a/types/webpack-dev-server/index.d.ts +++ b/types/webpack-dev-server/index.d.ts @@ -6,6 +6,7 @@ // Alan Agius // Artur Androsovych // Dave Cardwell +// Katsuya Hino // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -15,7 +16,7 @@ import * as express from 'express'; import * as serveStatic from 'serve-static'; import * as https from 'https'; import * as http from 'http'; -import { Url } from "url"; +import * as connectHistoryApiFallback from 'connect-history-api-fallback'; declare namespace WebpackDevServer { interface ListeningApp { @@ -33,23 +34,6 @@ declare namespace WebpackDevServer { type ProxyConfigArray = ProxyConfigArrayItem[]; - interface Context { - match: RegExpMatchArray; - parsedUrl: Url; - } - - type RewriteTo = (context: Context) => string; - - interface Rewrite { - from: RegExp; - to: string | RegExp | RewriteTo; - } - - interface HistoryApiFallbackConfig { - disableDotRule?: boolean; - rewrites?: Rewrite[]; - } - interface Configuration { /** Provides the ability to execute custom middleware after all other middleware internally within the server. */ after?: (app: express.Application, server: WebpackDevServer) => void; @@ -87,7 +71,7 @@ declare namespace WebpackDevServer { [key: string]: string; }; /** When using the HTML5 History API, the index.html page will likely have to be served in place of any 404 responses. */ - historyApiFallback?: boolean | HistoryApiFallbackConfig; + historyApiFallback?: boolean | connectHistoryApiFallback.Options; /** Specify a host to use. By default this is localhost. */ host?: string; /** Enable webpack's Hot Module Replacement feature. */ diff --git a/types/webpack-dev-server/webpack-dev-server-tests.ts b/types/webpack-dev-server/webpack-dev-server-tests.ts index f73d470f10..6f13a53234 100644 --- a/types/webpack-dev-server/webpack-dev-server-tests.ts +++ b/types/webpack-dev-server/webpack-dev-server-tests.ts @@ -90,6 +90,25 @@ const c4: WebpackDevServer.Configuration = { const c5: WebpackDevServer.Configuration = { proxy: [{context: (pathname: string) => true}] }; +const c6: WebpackDevServer.Configuration = { + historyApiFallback: { + disableDotRule: true, + htmlAcceptHeaders: ['text/html'], + index: '/app/', + logger: () => {}, + rewrites: [ + { + from: /\/page/, + to: '/page.html' + }, + { + from: /^\/images\/.*$/, + to: (context) => '/assets/' + context.parsedUrl.pathname + } + ], + verbose: true + } +}; // API example server = new WebpackDevServer(compiler, config);