From bedf3baa8802a2b6f50cc4d68651df64fd77eaa7 Mon Sep 17 00:00:00 2001 From: nael Date: Fri, 9 Sep 2016 09:39:03 -0400 Subject: [PATCH] Defintions for webpack dev server (#11087) * adding webpack-dev-server * renamed -test.ts to -tests.ts --- .../webpack-dev-server-tests.ts | 67 +++++++++++++++++++ webpack-dev-server/webpack-dev-server.d.ts | 55 +++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 webpack-dev-server/webpack-dev-server-tests.ts create mode 100644 webpack-dev-server/webpack-dev-server.d.ts diff --git a/webpack-dev-server/webpack-dev-server-tests.ts b/webpack-dev-server/webpack-dev-server-tests.ts new file mode 100644 index 00000000000000..df805219f94cde --- /dev/null +++ b/webpack-dev-server/webpack-dev-server-tests.ts @@ -0,0 +1,67 @@ +/// +/// + +import * as webpack from 'webpack'; +import * as WebpackDevServer from 'webpack-dev-server'; +var compiler = webpack({}); + +// basic example +var server = new WebpackDevServer(compiler, { + publicPath: "/assets/" +}); +server.listen(8080); + +// API example +server = new WebpackDevServer(compiler, { + // webpack-dev-server options + contentBase: "/path/to/directory", + // or: contentBase: "http://localhost/", + + hot: true, + // Enable special support for Hot Module Replacement + // Page is no longer updated, but a "webpackHotUpdate" message is send to the content + // Use "webpack/hot/dev-server" as additional module in your entry point + // Note: this does _not_ add the `HotModuleReplacementPlugin` like the CLI option does. + + // Set this as true if you want to access dev server from arbitrary url. + // This is handy if you are using a html5 router. + historyApiFallback: false, + + // Set this if you want to enable gzip compression for assets + compress: true, + + // Set this if you want webpack-dev-server to delegate a single path to an arbitrary server. + // Use "**" to proxy all paths to the specified server. + // This is useful if you want to get rid of 'http://localhost:8080/' in script[src], + // and has many other use cases (see https://github.com/webpack/webpack-dev-server/pull/127 ). + proxy: { + "**": "http://localhost:9090" + }, + + setup: function (app) { + // Here you can access the Express app object and add your own custom middleware to it. + // For example, to define custom handlers for some paths: + // app.get('/some/path', function(req, res) { + // res.json({ custom: 'response' }); + // }); + }, + + // pass [static options](http://expressjs.com/en/4x/api.html#express.static) to inner express server + staticOptions: { + }, + + // webpack-dev-middleware options + quiet: false, + noInfo: false, + lazy: true, + filename: "bundle.js", + watchOptions: { + aggregateTimeout: 300, + poll: 1000 + }, + // It's a required option. + publicPath: "/assets/", + headers: { "X-Custom-Header": "yes" }, + stats: { colors: true } +}); +server.listen(8080, "localhost", function () { }); \ No newline at end of file diff --git a/webpack-dev-server/webpack-dev-server.d.ts b/webpack-dev-server/webpack-dev-server.d.ts new file mode 100644 index 00000000000000..41abe0f8712e55 --- /dev/null +++ b/webpack-dev-server/webpack-dev-server.d.ts @@ -0,0 +1,55 @@ +// Type definitions for webpack-dev-server 1.12.1 +// Project: https://github.com/webpack/webpack-dev-server +// Definitions by: maestroh +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// +/// + +declare module "webpack-dev-server" { + import * as webpack from 'webpack'; + import * as core from 'express-serve-static-core'; + import * as serveStatic from 'serve-static'; + import * as http from 'http'; + + namespace WebpackDevServer { + export interface Configuration { + contentBase?: string; + hot?: boolean; + historyApiFallback?: boolean; + compress?: boolean; + proxy?: any; + staticOptions?: any; + quiet?: boolean; + noInfo?: boolean; + lazy?: boolean; + filename?: string; + watchOptions?: webpack.WatchOptions; + publicPath: string; + headers?: any; + stats?: webpack.compiler.StatsToJsonOptions | webpack.compiler.StatsToStringOptions; + + setup?(app: core.Express): void; + } + + export interface WebpackDevServer { + new ( + webpack: webpack.compiler.Compiler, + config: Configuration + ):WebpackDevServer; + + listen(port: number, + hostname: string, + callback?: Function + ): http.Server; + + listen(port: number, + callback?: Function + ): http.Server; + } + } + var wds: WebpackDevServer.WebpackDevServer; + + export = wds; +} \ No newline at end of file