Skip to content

Commit b3f9126

Browse files
feat: hapi support
1 parent 6d6e158 commit b3f9126

File tree

7 files changed

+1587
-832
lines changed

7 files changed

+1587
-832
lines changed

README.md

+81-2
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,83 @@ out completely._
540540

541541
Examples of use with other servers will follow here.
542542

543+
### Connect
544+
545+
```js
546+
const connect = require("connect");
547+
const http = require("http");
548+
const webpack = require("webpack");
549+
const webpackConfig = require("./webpack.config.js");
550+
const devMiddleware = require("webpack-dev-middleware");
551+
552+
const compiler = webpack(webpackConfig);
553+
const devMiddlewareOptions = {
554+
/** Your webpack-dev-middleware-options */
555+
};
556+
const app = connect();
557+
558+
app.use(devMiddleware(compiler, devMiddlewareOptions));
559+
560+
http.createServer(app).listen(3000);
561+
```
562+
563+
### Express
564+
565+
```js
566+
const express = require("express");
567+
const webpack = require("webpack");
568+
const webpackConfig = require("./webpack.config.js");
569+
const devMiddleware = require("webpack-dev-middleware");
570+
571+
const compiler = webpack(webpackConfig);
572+
const devMiddlewareOptions = {
573+
/** Your webpack-dev-middleware-options */
574+
};
575+
const app = express();
576+
577+
app.use(devMiddleware(compiler, devMiddlewareOptions));
578+
579+
app.listen(3000, () => console.log("Example app listening on port 3000!"));
580+
```
581+
582+
### Hapi
583+
584+
```js
585+
const Hapi = require("@hapi/hapi");
586+
const webpack = require("webpack");
587+
const webpackConfig = require("./webpack.config.js");
588+
const devMiddleware = require("webpack-dev-middleware");
589+
590+
const compiler = webpack(webpackConfig);
591+
const devMiddlewareOptions = {};
592+
593+
(async () => {
594+
const server = Hapi.server({ port: 3000, host: "localhost" });
595+
596+
await server.register({
597+
plugin: devMiddleware.hapiPlugin(),
598+
options: {
599+
// The `compiler` option is required
600+
compiler,
601+
...devMiddlewareOptions,
602+
},
603+
});
604+
605+
await server.start();
606+
607+
console.log("Server running on %s", server.info.uri);
608+
})();
609+
610+
process.on("unhandledRejection", (err) => {
611+
console.log(err);
612+
process.exit(1);
613+
});
614+
```
615+
616+
### Koa
617+
618+
Soon...
619+
543620
### Fastify
544621

545622
Fastify interop will require the use of `fastify-express` instead of `middie` for providing middleware support. As the authors of `fastify-express` recommend, this should only be used as a stopgap while full Fastify support is worked on.
@@ -551,11 +628,13 @@ const webpackConfig = require("./webpack.config.js");
551628
const devMiddleware = require("webpack-dev-middleware");
552629

553630
const compiler = webpack(webpackConfig);
554-
const { publicPath } = webpackConfig.output;
631+
const devMiddlewareOptions = {
632+
/** Your webpack-dev-middleware-options */
633+
};
555634

556635
(async () => {
557636
await fastify.register(require("fastify-express"));
558-
await fastify.use(devMiddleware(compiler, { publicPath }));
637+
await fastify.use(devMiddleware(compiler, devMiddlewareOptions));
559638
await fastify.listen(3000);
560639
})();
561640
```

0 commit comments

Comments
 (0)