Defintions for webpack dev server (#11087)

* adding webpack-dev-server

* renamed -test.ts to -tests.ts
This commit is contained in:
nael
2016-09-09 09:39:03 -04:00
committed by Masahiro Wakame
parent 17f7f965f5
commit bedf3baa88
2 changed files with 122 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
/// <reference path="webpack-dev-server.d.ts" />
/// <reference path="../webpack/webpack.d.ts"/>
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 () { });

View File

@@ -0,0 +1,55 @@
// Type definitions for webpack-dev-server 1.12.1
// Project: https://github.com/webpack/webpack-dev-server
// Definitions by: maestroh <https://github.com/maestroh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../webpack/webpack.d.ts" />
/// <reference path="../serve-static/serve-static.d.ts" />
/// <reference path="../express-serve-static-core/express-serve-static-core.d.ts" />
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;
}