hapi-webpack-connection
Bridge between Hapi and Webpack
Installation
npm install hapi-webpack-connection
API
WebpackConnection([options])
The WebpackConnection()
function is a top-level function exported by the hapi-webpack-connection
module.
var WebpackConnection = ;var Webpack = ;
Creates a Webpack
object where:
-
options
- optional webpack configuration object. See the webpack documentation for all available options.This object includes also the
webpack-dev-server
configuration via thedevServer
property. See the webpack-dev-server documentation for all available options.If omitted, the module will try to read the
webpack.config.js
file in the current working directory. This file should export the configuration object:moduleexports =// configuration;This is the defaults merged with the options by the module:
// Defaut configurationdevServer:contentBase: processfilename: null // Get from output.filenamehistoryApiFallback: falsehost: 'localhost'port: 0 // 0 = Randomly selectedhot: falsehttps: falseinline: falselazy: falsenoInfo: falseoutputPath: '/'publicPath: null // Get from output.publicPathproxy: {}quiet: falsestats:cached: falsecachedAssets: false// colors: true or false, turned on if the terminal supports itcontext: processoutput:filename: 'bundle.js'path: processpublicPath: '/'
Webpack properties
webpack.compiler
The webpack compiler
instance.
var WebpackConnection = ;var Webpack = ; Webpackcompiler;
webpack.connection
The hapi connection
configuration object. See the hapi documentaion for all available options.
The connection has a webpack
label and exposes the webpack configuration via app.webpack
which can later be accessed via connection.settings.app.webpack
.
var WebpackConnection = ;var Webpack = ; var Hapi = ;var server = ; server; serverstart { console;};
webpack.getAssets()
Returns an object where each key is the name of the chunk and the value is the full url of the chunk.
This object will not have any properties until the compilation is done.
var webpackConfig = entry: main: './entry.js' output: publicPath: '/assets' filename: '[name]-compiled.js' devServer: port: 3001 ; var WebpackConnection = ;var Webpack = ; console;// Compiling...// Print:// {} console;// Compiled...// Print:// {// main: 'http://localhost:3001/assets/main-compiled.js'// }
Examples
Using hot-reloading
var webpackConfig = entry: './entry.js' output: path: __dirname + '/dist' devServer: port: 3000 inline: true hot: true // The entry will become// [// 'webpack-dev-server/client?http://localhost:3000', // from inline// 'webpack/hot/dev-server', // from inline and hot// './entry.js'// ] var Hapi = ;var Webpack = webpackConfig; var server = ;server; serverstart { console;};
Using getAssets()
var Hapi = ;var Webpack = ; var server = ;server; server; server; serverstart { console;};
Using glue
var Glue = ;var Webpack = ; var manifest = connections: Webpackconnection port: 3001 labels: 'myApp' server: // ... some server options plugins: // ... some plugins to register Glue;
Licence
The MIT License (MIT)
Copyright (c) 2015 Simon Degraeve
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.