diff --git a/types/koa-webpack/index.d.ts b/types/koa-webpack/index.d.ts new file mode 100644 index 0000000000..b425956f03 --- /dev/null +++ b/types/koa-webpack/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for koa-webpack 1.0 +// Project: https://github.com/shellscape/koa-webpack#readme +// Definitions by: Luka Maljic +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import Koa = require('koa'); +import webpack = require('webpack'); +import webpackDevMiddleware = require('webpack-dev-middleware'); +import webpackHotMiddleware = require('webpack-hot-middleware'); +import connect = require('connect'); + +declare function koaWebpack( + options?: koaWebpack.Options +): Koa.Middleware & koaWebpack.CombinedWebpackMiddleware; + +declare namespace koaWebpack { + interface Options { + compiler?: webpack.Compiler; + config?: webpack.Configuration; + dev?: webpackDevMiddleware.Options; + hot?: webpackHotMiddleware.Options; + } + + interface CombinedWebpackMiddleware { + dev: connect.NextHandleFunction & webpackDevMiddleware.WebpackDevMiddleware; + hot: connect.NextHandleFunction & webpackHotMiddleware.EventStream; + } +} + +export = koaWebpack; diff --git a/types/koa-webpack/koa-webpack-tests.ts b/types/koa-webpack/koa-webpack-tests.ts new file mode 100644 index 0000000000..c153a874d5 --- /dev/null +++ b/types/koa-webpack/koa-webpack-tests.ts @@ -0,0 +1,47 @@ +import Koa = require('koa'); +import webpack = require('webpack'); +import koaWebpack = require('koa-webpack'); + +const app = new Koa(); +const config: webpack.Configuration = {}; +const compiler = webpack(config); + +// Using the middleware + +const middleware = koaWebpack({ + compiler, + config, + dev: { + noInfo: false, + quiet: false, + lazy: true, + watchOptions: { + aggregateTimeout: 300, + poll: true, + }, + publicPath: '/assets/', + index: 'index.html', + headers: { + 'X-Custom-Header': 'yes' + }, + stats: { + colors: true, + }, + reporter: null, + serverSideRender: false + }, + hot: { + log: console.log.bind(console), + path: '/__what', + heartbeat: 2000 + } +}); + +app.use(middleware); + +// Accessing the underlying middleware + +middleware.dev.close(); +middleware.dev.invalidate(); +middleware.dev.waitUntilValid(); +middleware.hot.publish(null); diff --git a/types/koa-webpack/tsconfig.json b/types/koa-webpack/tsconfig.json new file mode 100644 index 0000000000..d3cef374db --- /dev/null +++ b/types/koa-webpack/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "koa-webpack-tests.ts" + ] +} diff --git a/types/koa-webpack/tslint.json b/types/koa-webpack/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/koa-webpack/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }