hapi-webpack-dev-server-plugin
This is a plugin for hapijs providing the necessary routes to function as a webpack-dev-server for the awesome webpack project directly in hapijs. The actual Webpack-dev-server is implemented with express.js and since we are heavily using the fabulous hapijs as our main backend framework we found it very useful to have everything right there. This avoids tweaking SOP related things just for dev purposes.
Just like the original webpack-dev-server we also want to give out a quick warning:
DON'T USE THIS PLUGIN IN PRODUCTION!
>= v1.1.2 -> Requirements: hapijs ^14.x.x
< v1.1.2 -> Requirements: hapijs ^8.x.x
State: In Progress (meaning not hot code replacement at the moment, but auto relaoding works just fine)
Basic Usage
we tend to structure our apps like
- server_plugin indexjs- webpack_frontend - src mainjs webpackconfigjsserverjs
with that structure in mind you'd setup the dev-server-plugin in the server.js as follows
var Webpack = ;var Hapi = ; //basic webpack config, see webpack api docs for all optionsvar webpackConf = ;webpackConfentry = app: './webpack_frontend/src/main.js' //this is needed to have the correct relative paths for the webpack compiler which now runs from the base dir rather than from webpack_frontend;webpackConfdevtool = 'source-map'; //create the webpack compilercompiler = ; //create hapi serverserver = ;server; //start server and register dev server as pluginserverstart { server;};
Config Options
- compiler - the webpack compiler
- devIndex - path to the dev index.html file. Is ignored if devView is configured. defaults to index.html in the cwd
- devView
name: "the name of the view" // mandatory, elsewise the devIndex will be used data: "tplData" // an object, a function which gets passed in the request, or empty - data is supposed to determine tplData for the view
- quiet - turns off webpack compiler logging
- watchDelay - determines how frequently file changes are monitored
- headers - hash of headers to add to webpack-dev-server-plugin served files
Questions?
Feel free to ask questions if anything is badly described!
info@atroo.de or an Issue!