hapi-webpack-plugin

raw JSON →
3.0.0 verified Sat May 09 auth: no javascript maintenance

Webpack middleware plugin for Hapi.js that integrates webpack-dev-middleware and webpack-hot-middleware to enable Hot Module Replacement (HMR) during development. Version 3.0.0 supports Hapi >= 17.x and webpack >= 2.x. It offers two usage modes: passing an object with compiler/assets/hot options, or a path to a webpack config file. Compared to alternatives like hapi-webpack-dev-middleware, this plugin bundles both middlewares and supports HMR out of the box. Release cadence is sporadic; last release was in 2018, and it is considered stable but unmaintained.

error Error: Cannot find module 'webpack-dev-middleware'
cause Missing webpack-dev-middleware dependency.
fix
npm install webpack-dev-middleware --save-dev
error TypeError: compiler is not a function
cause Webpack compiler not initialized correctly.
fix
Call Webpack(config) to create compiler, then pass it.
error AssertionError: options.compiler must be a webpack compiler instance
cause Options missing 'compiler' property or it's not a valid compiler.
fix
Pass {compiler, assets, hot} in options.
breaking Version 3.0.0 only works with Hapi >= 17.x; does not support Hapi 16.x or older.
fix Use version 2.x.x for Hapi <= 16.x.
deprecated The 'hapi' package is deprecated; use '@hapi/hapi' for Hapi v17+.
fix Install @hapi/hapi instead of hapi.
gotcha The plugin expects 'compiler' property in options; misspelling or missing will cause silent failure.
fix Ensure options object includes 'compiler', 'assets', and 'hot' correctly.
gotcha When using path option, the webpack config file must export a valid configuration object, not a function.
fix Export an object from webpack.config.js.
deprecated Hapi v16 callback style registration is deprecated; use async/await with Hapi v17.
fix Upgrade to Hapi v17+ and use async registration.
npm install hapi-webpack-plugin
yarn add hapi-webpack-plugin
pnpm add hapi-webpack-plugin

Registers the hapi-webpack-plugin with Hapi v17+, passing a webpack compiler and enabling HMR.

import {Server} from '@hapi/hapi';
import Webpack from 'webpack';
import WebpackPlugin from 'hapi-webpack-plugin';

const server = new Server({port: 3000});
const compiler = Webpack({
  entry: './src/index.js',
  output: {path: __dirname + '/dist', filename: 'bundle.js'},
  mode: 'development'
});

async function start() {
  await server.register({
    plugin: WebpackPlugin,
    options: {
      compiler,
      assets: {publicPath: '/'},
      hot: true
    }
  });
  await server.start();
  console.log('Server running at:', server.info.uri);
}
start().catch(console.error);