Skip to content

Commit a3d3564

Browse files
committed
Initial commit.
0 parents  commit a3d3564

11 files changed

Lines changed: 577 additions & 0 deletions

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
9+
[*.{js,json,ts,yml}]
10+
indent_style = space
11+
indent_size = 2

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Node.js modules
2+
node_modules/
3+
4+
# Built files
5+
dist/

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Exclude TypeScript source files
2+
src/

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: node_js
2+
3+
node_js:
4+
- node
5+
6+
if: tag IS present
7+
8+
script: "yarn build"
9+
10+
deploy:
11+
provider: npm
12+
email:
13+
secure: a2W//hLn8LV4M40Lrg2609maGml/MDdyyIG6itQQYieXw7cOGyrpbefffDUQT8rTrV1kv/+zgHV8peNnJuAbSHBTRwlmun3M6JOq0Mfoo+xuQcgx4kPBpI1w6Up3KXEJmrETF5wa1MK4i37kmlPwQnD0qD34WzBpuKBE+TdDvMbVYG4/Wvo2AXZ/QZnRF6q2earTFGIvYUFGWL0uOECaqEhuH0cF/fzTwEolTs/lf75zbcFHCX6X9vSVGGeY0UXaOa+GrLW44Y4o2SwrvFSfaONnhpNZ3Bei/mXtPW3j8Gj+jgzMio7hXxE+KprabbWzBxQvAhl5Ij5GeJH9qne9M047SVieRFHuvSzYQ0GBz/OvhKvJhJpSF7aLMHOz+KQuPu+Tx8dapgQsiTTm4bB3CTA1oynIw0e3UnDWRMNZUdArw4wIxQtVufvd43f+r33lMHzxKRPCE3Ny5uFGMSVR6PL2fvr/oF2bEq6MLUcAEJ5MNn6r+u3g1kQdqJfyClmwN7NV2aXHYk9VeelNIsNZMWuhp0rB6z3G4xZgMm7NoGkjJE6mSNarM+3CsVT++0pxupXsazkBbsbW9cnAk1bldE0Q1r82URT19NU6IoqJSdk0wAmyXyU/IxeiugV9lwJPjRgpSE4WeD1lC7wW1tQysbX/bRlGD+YEQDEgFmKjNhs=
14+
api_key:
15+
secure: WlKFl/7BsG0Ai7W64/osnvdIppFKWq91ivFj+4jAu695J25vxc4vE9qCzeYe6vkJhqNtl5cLa4qdDYbq2O6tP8w+eBy/toRJuIsl9vACsDxK1s7X19MSp4nq1m28c2cOp/WuWGwjVBnXKAt/IqUionF4SXgqLuJJWtfbB39kOjqAeR7SwWVS5FfMizI0GxV6qUhzgAEMXk9l8ZvTkkXUSGEzuZf8lP90pa+ggOsUYMn9lvqw6KMePx9IcMWtH9I4UFek7Qi0k9Ayas+0hcCki+1jEZSKryu3zu/grkE9tsHz4igj0OowgCy1vkk3wZfyKnVH+ryA8u96nOIBBNAvoTjZkS+/YON4KalYDAJAogWT/p2/+VUVX2S2+wMtiS/eo9dfqPEh5Mdq/ZhT64O1D8tktFxzSvB8FZ1SJZZOfFZnzNsTI71AEbNUl1rYQ/F0Bv768+1Yf5uf21PQfftzDl48ftIg0nvuesjmBdgoHAoUQXY5Ib6mJOYGSU+atRk5tO2kem3wvMt+PMK9gdfELYkEm93O+NculmvQpiOgoAuVT/680JcN+TKFWSQkGyWEM7Hkfmfv2uICRUMRVbpg8vR/gOzs4cRUExOBmHEZIMzdZGVu/MHYZZyUYvZckk/elmcDWBXZfhX8Y5IkNvJYqk8JkhprAXnWkK6XJir7UEo=
16+
on:
17+
tags: true

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# webpack-dev-server-plugin [![npm version](https://badge.fury.io/js/%40glints%2Feslint-config.svg)](https://badge.fury.io/js/%40glints%2Fhapi-webpack-dev-server-plugin)
2+
3+
This allows `webpack-dev-middleware` to be used with hapi.
4+
5+
# Usage Instructions
6+
7+
To integrate this into your project, install the package:
8+
9+
```
10+
npm install --save @glints/hapi-webpack-dev-server-plugin # If using npm
11+
yarn add @glints/hapi-webpack-dev-server-plugin # If using Yarn
12+
```
13+
14+
Then register the plugin with hapi:
15+
16+
```js
17+
// Create an instance of the Webpack compiler.
18+
const compiler = Webpack({
19+
// Compiler options here.
20+
});
21+
22+
// Register the plugin with the hapi server.
23+
await hapiServer.register({
24+
plugin: WebpackDevServerPlugin,
25+
options: {
26+
compiler,
27+
devMiddlewareOptions: {
28+
// Define options for webpack-dev-middleware
29+
publicPath: webpackConfig.output.publicPath,
30+
stats: {
31+
modules: false,
32+
},
33+
},
34+
},
35+
});
36+
```
37+
38+
# Contribution Guidelines
39+
40+
We use [EditorConfig](https://editorconfig.org) to maintain consistent line-ending and indentation rules across all our projects. Ensure that you have the appropriate plugin installed in your preferred editor, or refer to `.editorconfig`.
41+
42+
# About Glints
43+
44+
Glints is an online talent recruitment and career discovery platform headquartered in Singapore. It is a platform for young talent to build up their career readiness through internships and graduate jobs; developing skill sets required in different careers.
45+
46+
**P.S.** We deal with quite a number of interesting engineering problems centered on matching the right talent to employers. Sounds interesting? Send your resume to tech@glints.com.

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@glints/hapi-webpack-dev-server-plugin",
3+
"version": "1.0.0",
4+
"description": "A plugin for hapi to expose webpack-dev-server.",
5+
"main": "./dist/index.js",
6+
"types": "./dist/index.d.ts",
7+
"repository": "https://github.com/glints-dev/hapi-plugins",
8+
"author": "Wong Yong Jie <yjwong92@gmail.com>",
9+
"license": "MIT",
10+
"private": false,
11+
"scripts": {
12+
"build": "tsc --declaration",
13+
"clean": "rm -r dist/",
14+
"tslint": "tslint --project ."
15+
},
16+
"devDependencies": {
17+
"@glints/tslint-rules": "^1.0.5",
18+
"@types/hapi": "^17.0.19",
19+
"@types/webpack": "^4.4.11",
20+
"@types/webpack-dev-middleware": "^2.0.2",
21+
"@types/webpack-hot-middleware": "^2.16.4",
22+
"tslint": "^5.11.0",
23+
"typescript": "^3.0.3"
24+
},
25+
"peerDependencies": {
26+
"hapi": ">= 17",
27+
"webpack": ">= 4",
28+
"webpack-dev-middleware": ">= 3",
29+
"webpack-hot-middleware": ">= 2"
30+
}
31+
}

src/WebpackDevServerPlugin.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import * as Hapi from 'hapi';
2+
import * as Webpack from 'webpack';
3+
4+
import * as WebpackDevMiddleware from 'webpack-dev-middleware';
5+
import * as WebpackHotMiddleware from 'webpack-hot-middleware';
6+
7+
export interface WebpackDevServerPluginOptions {
8+
compiler: Webpack.Compiler;
9+
devMiddlewareOptions: WebpackDevMiddleware.Options;
10+
}
11+
12+
export interface WebpackDevServerPluginProperties {
13+
devMiddleware: WebpackDevMiddleware.WebpackDevMiddleware;
14+
}
15+
16+
declare module 'hapi' {
17+
interface PluginProperties {
18+
WebpackDevServerPlugin?: WebpackDevServerPluginProperties;
19+
}
20+
}
21+
22+
/**
23+
* WebpackDevServerPlugin provides access to the Webpack development server.
24+
*/
25+
const WebpackDevServerPlugin: Hapi.Plugin<WebpackDevServerPluginOptions> & Hapi.PluginNameVersion = {
26+
name: 'WebpackDevServerPlugin',
27+
register: async (server, options) => {
28+
const webpackDevMiddleware = WebpackDevMiddleware(options.compiler, options.devMiddlewareOptions);
29+
const webpackHotMiddleware = WebpackHotMiddleware(options.compiler, {
30+
path: '/__webpack_hmr',
31+
});
32+
33+
server.ext('onRequest', async (request, h) => {
34+
try {
35+
await webpackDevMiddleware(request.raw.req, request.raw.res, (err: Error) => {
36+
// webpack-dev-middleware never calls the callback with an err object.
37+
// See node_modules/webpack-dev-middleware/lib/middleware.js.
38+
});
39+
return h.continue;
40+
} catch (err) {
41+
return err;
42+
}
43+
});
44+
45+
server.ext('onRequest', async (request, h) => {
46+
try {
47+
await new Promise((resolve, reject) => {
48+
webpackHotMiddleware(request.raw.req, request.raw.res, (err: Error) => {
49+
if (err) {
50+
reject(err);
51+
} else {
52+
resolve();
53+
}
54+
});
55+
});
56+
return h.continue;
57+
} catch (err) {
58+
return err;
59+
}
60+
});
61+
62+
server.expose('devMiddleware', webpackDevMiddleware);
63+
},
64+
};
65+
66+
export default WebpackDevServerPlugin;

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export {
2+
default as WebpackDevServerPlugin,
3+
WebpackDevServerPluginOptions,
4+
WebpackDevServerPluginProperties,
5+
} from './WebpackDevServerPlugin';

tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compileOnSave": false,
3+
"compilerOptions": {
4+
"lib":[
5+
"es2015"
6+
],
7+
"outDir": "dist",
8+
"sourceMap": true,
9+
"sourceRoot": "src",
10+
"strict": true
11+
}
12+
}

tslint.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@glints/tslint-rules/tslint-base"
3+
}

0 commit comments

Comments
 (0)