Skip to content

Commit

Permalink
koa-webpack v5
Browse files Browse the repository at this point in the history
  • Loading branch information
tlaziuk committed Jun 5, 2018
1 parent 3f85ee6 commit c1120c2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
16 changes: 9 additions & 7 deletions types/koa-webpack/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Type definitions for koa-webpack 1.0
// Project: https://github.com/shellscape/koa-webpack#readme
// Type definitions for koa-webpack 5.0
// Project: https://github.com/shellscape/koa-webpack
// Definitions by: Luka Maljic <https://github.com/malj>
// Tomek Łaziuk <https://github.com/tlaziuk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

Expand All @@ -12,19 +13,20 @@ import connect = require('connect');

declare function koaWebpack(
options?: koaWebpack.Options
): Koa.Middleware & koaWebpack.CombinedWebpackMiddleware;
): Promise<Koa.Middleware & koaWebpack.CombinedWebpackMiddleware>;

declare namespace koaWebpack {
interface Options {
compiler?: webpack.Compiler;
config?: webpack.Configuration;
dev?: webpackDevMiddleware.Options;
hot?: webpackHotMiddleware.Options | boolean;
devMiddleware?: webpackDevMiddleware.Options;
hotClient?: webpackHotMiddleware.Options | boolean;
}

interface CombinedWebpackMiddleware {
dev: connect.NextHandleFunction & webpackDevMiddleware.WebpackDevMiddleware;
hot: connect.NextHandleFunction & webpackHotMiddleware.EventStream;
devMiddleware: connect.NextHandleFunction & webpackDevMiddleware.WebpackDevMiddleware;
hotClient: connect.NextHandleFunction & webpackHotMiddleware.EventStream;
close(callback?: () => any): void;
}
}

Expand Down
26 changes: 16 additions & 10 deletions types/koa-webpack/koa-webpack-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const compiler = webpack(config);

// Using the middleware

const middleware = koaWebpack({
koaWebpack({
compiler,
config,
dev: {
devMiddleware: {
lazy: true,
watchOptions: {
aggregateTimeout: 300,
Expand All @@ -28,18 +28,24 @@ const middleware = koaWebpack({
reporter: null,
serverSideRender: false
},
hot: {
hotClient: {
log: console.log.bind(console),
path: '/__what',
heartbeat: 2000
}
});
}).then((middleware) => {
app.use(middleware);

// Accessing the underlying middleware

app.use(middleware);
middleware.devMiddleware.close();
middleware.devMiddleware.invalidate();
middleware.devMiddleware.waitUntilValid();
middleware.hotClient.publish(null);

// Accessing the underlying middleware
return middleware;
}).then((middleware) => {
// close the middleware

middleware.dev.close();
middleware.dev.invalidate();
middleware.dev.waitUntilValid();
middleware.hot.publish(null);
middleware.close();
});

0 comments on commit c1120c2

Please sign in to comment.