Coder Social home page Coder Social logo

hapi-webpack-plugin's Introduction

hapi-webpack-plugin

Maintenance Status Dependency Status NPM version

Webpack middleware for Hapi. Supports HMR.

Webpack Version

Please download the appropriate version for you.

Hapi >= 17.x

  • For webpack >= 2.x use version >= 3.0.0 of this package.

Hapi <= 16.x

  • For webpack 1.x use version < 1.3.0 of this package.
  • For webpack 2.x use version 2.x.x of this package.

Installation

npm install hapi-webpack-plugin

Usage

See webpack-dev-middleware and webpack-hot-middleware for all available options.

You can use the plugin in two ways.

1) With object as options

Hapi >= 17.x

/**
 * file: index.js
 */

/**
 * Import dependencies
 */
import {Server} from 'hapi';
import Webpack from 'webpack';
import WebpackPlugin from 'hapi-webpack-plugin';

/**
 * Create server
 */
const server = new Server({port: 3000});

/**
 * Define constants
 */
const compiler = new Webpack({
  // webpack configuration
  entry: 'app.js'
});

const assets = {
  // webpack-dev-middleware options
  // See https://github.com/webpack/webpack-dev-middleware
}

const hot = {
  // webpack-hot-middleware options
  // See https://github.com/glenjamin/webpack-hot-middleware
}

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

start();

Hapi <= 16.x

/**
 * file: index.js
 */

/**
 * Import dependencies
 */
import {Server} from 'hapi';
import Webpack from 'webpack';
import WebpackPlugin from 'hapi-webpack-plugin';

/**
 * Create server
 */
const server = new Server();
server.connection({port: 3000});

/**
 * Define constants
 */
const compiler = new Webpack({
  // webpack configuration
  entry: 'app.js'
});

const assets = {
  // webpack-dev-middleware options
  // See https://github.com/webpack/webpack-dev-middleware
}

const hot = {
  // webpack-hot-middleware options
  // See https://github.com/glenjamin/webpack-hot-middleware
}

/**
 * Register plugin and start server
 */
server.register({
  register: WebpackPlugin,
  options: {compiler, assets, hot}
},
error => {
  if (error) {
    return console.error(error);
  }
  server.start(() => console.log('Server running at:', server.info.uri));
});

2) With path as options

Hapi >= 17

/**
 * file: index.js
 */

/**
 * Import dependencies
 */
import {Server} from 'hapi';
import WebpackPlugin from 'hapi-webpack-plugin';


/**
 * Create server
 */
const server = new Server({port: 3000});

/**
 * Register plugin and start server
 */
async function start() {
  try {
    await server.register({
      plugin: WebpackPlugin,
      options: './webpack.config.js'
    });
  }
  catch (error) {
    console.error(error);
  }
  
  try {
    server.start();
    console.log('Server running at:', server.info.uri)
  }
  catch (error) {
    console.error(error);
  }
}

start();

Hapi <= 16.x

/**
 * file: index.js
 */

/**
 * Import dependencies
 */
import {Server} from 'hapi';
import WebpackPlugin from 'hapi-webpack-plugin';


/**
 * Create server
 */
const server = new Server();
server.connection({port: 3000});

/**
 * Register plugin and start server
 */
server.register({
  register: WebpackPlugin,
  options: './webpack.config.js'
},
error => {
  if (error) {
    return console.error(error);
  }
  server.start(() => console.log('Server running at:', server.info.uri));
});
/**
 * file: webpack.config.js
 */

/**
 * Export webpack configuration
 */
export default {
  entry: 'app.js',

  // webpack-dev-middleware options
  // See https://github.com/webpack/webpack-dev-middleware
  assets: {},

  // webpack-hot-middleware options
  // See https://github.com/glenjamin/webpack-hot-middleware
  hot: {}
};

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.

hapi-webpack-plugin's People

Contributors

mashaalmemon avatar simondegraeve avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hapi-webpack-plugin's Issues

Hot options not working

Hello Simon,

I am trying to activate the reload function for webpack-hot-middleware like this:

var hot = {
  // webpack-hot-middleware options 
  // See https://github.com/glenjamin/webpack-hot-middleware 
  reload:true
}

The asset's options do work though. And if I set reload to true in the webpack's entry settings works as well.

Webpack 4 compatibility

When using webpack4, I get the following error. I think it s due to webpack3 dependency mixing with webpack4 new plugin system.

TypeError: Cannot read property 'additionalPass' of undefined at HotModuleReplacementPlugin.apply (/Users/vraptor/WebDev/test/node_modules/webpack/lib/HotModuleReplacementPlugin.js:32:18) at Compiler.apply (/Users/vraptor/WebDev/test/node_modules/hapi-webpack-plugin/node_modules/tapable/lib/Tapable.js:375:16) at new webpack (/Users/vraptor/WebDev/test/node_modules/hapi-webpack-plugin/node_modules/webpack/lib/webpack.js:33:19) at Object.register (/Users/vraptor/WebDev/test/node_modules/hapi-webpack-plugin/lib/index.js:44:16)

Any idea ?
Thanks

Use with Handlebars

Is it possible to use this with Hapi Views and Handlebars? My files seem to be served to the browser as expected but all of my template strings ({{example}}) are ignored/not expanded.

Let me know if there is any other info I can provide.

Thanks in advance for any help!

webpack.config.js with ES6 exports does not work

Consider the example someone else posted: https://github.com/adam-beck/hapi-plz

If you apply this patch, everything breaks although ES6 exports should work with "the second way" mentioned in usage:

diff --git a/package.json b/package.json
index fb601cc..1249129
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
   "description": "",
   "main": "index.js",
   "scripts": {
-    "dev": "node dev-server.js",
+    "dev": "babel-node dev-server.js",
     "test": "echo \"Error: no test specified\" && exit 1"
   },
   "keywords": [],
@@ -21,6 +21,7 @@
     "webpack": "^1.13.0"
   },
   "dependencies": {
+    "babel-cli": "^6.8.0",
     "hapi": "^13.3.0",
     "react": "^15.0.1",
     "react-dom": "^15.0.1"
diff --git a/webpack.config.js b/webpack.config.js
index ae00368..c5e09aa 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -3,7 +3,7 @@ const webpack = require('webpack');

 const HtmlWebpackPlugin = require('html-webpack-plugin');

-module.exports = {
+export default ({
   entry: [
     'webpack-hot-middleware/client',
     './src/index.js'
@@ -34,4 +34,4 @@ module.exports = {
       colors: true
     }
   }
-};
+});

The error is:

C:\devel\hapi-plz\node_modules\webpack-dev-middleware\middleware.js:106
                        if(err) throw err;
                                ^
 Error: invalid argument
    at pathToArray (C:\devel\hapi-plz\node_modules\memory-fs\lib\MemoryFileSystem.js:44:10)
    at MemoryFileSystem.mkdirpSync (C:\devel\hapi-plz\node_modules\memory-fs\lib\MemoryFileSystem.js:139:13)
    at MemoryFileSystem.(anonymous function) [as mkdirp] (C:\devel\hapi-plz\node_modules\memory-fs\lib\MemoryFileSystem.js:279:34)
    at Compiler.<anonymous> (C:\devel\hapi-plz\node_modules\webpack\lib\Compiler.js:229:25)
    at Compiler.applyPluginsAsync (C:\devel\hapi-plz\node_modules\tapable\lib\Tapable.js:60:69)
    at Compiler.emitAssets (C:\devel\hapi-plz\node_modules\webpack\lib\Compiler.js:226:7)
    at Watching.<anonymous> (C:\devel\hapi-plz\node_modules\webpack\lib\Compiler.js:54:18)
    at C:\devel\hapi-plz\node_modules\webpack\lib\Compiler.js:403:12
    at Compiler.next (C:\devel\hapi-plz\node_modules\tapable\lib\Tapable.js:67:11)
    at Compiler.<anonymous> (C:\devel\hapi-plz\node_modules\webpack\lib\CachePlugin.js:40:4)
    at Compiler.applyPluginsAsync (C:\devel\hapi-plz\node_modules\tapable\lib\Tapable.js:71:13)
    at Compiler.<anonymous> (C:\devel\hapi-plz\node_modules\webpack\lib\Compiler.js:400:9)
    at Compilation.<anonymous> (C:\devel\hapi-plz\node_modules\webpack\lib\Compilation.js:577:13)
    at Compilation.applyPluginsAsync (C:\devel\hapi-plz\node_modules\tapable\lib\Tapable.js:60:69)
    at Compilation.<anonymous> (C:\devel\hapi-plz\node_modules\webpack\lib\Compilation.js:572:10)
    at Compilation.applyPluginsAsync (C:\devel\hapi-plz\node_modules\tapable\lib\Tapable.js:60:69)

npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\opt\\node\\node.exe" "C:\\opt\\node\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
npm ERR! node v5.10.1
npm ERR! npm  v3.8.7
npm ERR! code ELIFECYCLE
npm ERR! [email protected] dev: `babel-node dev-server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script 'babel-node dev-server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the hapi-plz package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     babel-node dev-server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs hapi-plz
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls hapi-plz
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\devel\hapi-plz\npm-debug.log

Any ideas how to setup this with Babel? Everything works fine if I use the plugin via "the first way"

Invalid path ''

Hi,

I'm experiencing this error, and I can't guess how to solve it.

Error trace is:

/home/karlas/code/kaitocat/node_modules/hapi-webpack-plugin/node_modules/webpack-dev-middleware/middleware.js:104
            if(err) throw err;
                          ^
Error: Invalid path ''
    at pathToArray (/home/karlas/code/kaitocat/node_modules/hapi-webpack-plugin/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:27:38)
    at MemoryFileSystem.mkdirpSync (/home/karlas/code/kaitocat/node_modules/hapi-webpack-plugin/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:111:13)
    at MemoryFileSystem.(anonymous function) [as mkdirp] (/home/karlas/code/kaitocat/node_modules/hapi-webpack-plugin/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:193:34)
    at Compiler.<anonymous> (/home/karlas/code/kaitocat/node_modules/hapi-webpack-plugin/node_modules/webpack/lib/Compiler.js:229:25)
    at Compiler.applyPluginsAsync (/home/karlas/code/kaitocat/node_modules/hapi-webpack-plugin/node_modules/webpack/node_modules/tapable/lib/Tapable.js:60:69)
    at Compiler.emitAssets (/home/karlas/code/kaitocat/node_modules/hapi-webpack-plugin/node_modules/webpack/lib/Compiler.js:226:7)
    at Watching.<anonymous> (/home/karlas/code/kaitocat/node_modules/hapi-webpack-plugin/node_modules/webpack/lib/Compiler.js:54:18)
    at /home/karlas/code/kaitocat/node_modules/hapi-webpack-plugin/node_modules/webpack/lib/Compiler.js:403:12
    at Compiler.next (/home/karlas/code/kaitocat/node_modules/hapi-webpack-plugin/node_modules/webpack/node_modules/tapable/lib/Tapable.js:67:11)
    at Compiler.<anonymous> (/home/karlas/code/kaitocat/node_modules/hapi-webpack-plugin/node_modules/webpack/lib/CachePlugin.js:40:4)

This appears some seconds after registering, not inmediately. Register code is, at /src/server/index.js file of my project

  server.register(
  {
    register : require('hapi-webpack-plugin'),
    options  : path.join(__dirname, '../../webpack.config.js')
  }, function(err)
  {
    if (err)
    {
      return console.error(err);  //this is not reached
    }
  });

Webpack-dev-server is working fine when executing standalone via terminal. Could the problem be to have files in different paths? (webpack.config.js is at root of project)

Thanks in advance

Error

I receive the following error when trying to load up the plugin. Any idea what this might be pointing to? I'm assuming this has something to do with hapi and webpack as I don't receive information otherwise. Apologies if this is not related to the plugin.

> babel-node lib/server.js

/Users/kevinpruett/Code/clab/node_modules/tapable/lib/Tapable.js:164
        arguments[i].apply(this);
                    ^

TypeError: Cannot read property 'apply' of undefined
    at Compiler.apply (/Users/kevinpruett/Code/clab/node_modules/tapable/lib/Tapable.js:164:15)
    at OptionsApply.WebpackOptionsApply.process (/Users/kevinpruett/Code/clab/node_modules/webpack/lib/WebpackOptionsApply.js:62:18)
    at new webpack (/Users/kevinpruett/Code/clab/node_modules/webpack/lib/webpack.js:22:48)
    at Object.<anonymous> (server.js:10:18)
    at Module._compile (module.js:397:26)
    at loader (/Users/kevinpruett/Code/clab/node_modules/babel-register/lib/node.js:130:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/kevinpruett/Code/clab/node_modules/babel-register/lib/node.js:140:7)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:429:10)
    at /Users/kevinpruett/Code/clab/node_modules/babel-cli/lib/_babel-node.js:161:27
    at Object.<anonymous> (/Users/kevinpruett/Code/clab/node_modules/babel-cli/lib/_babel-node.js:162:7)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)

HMR check route is 404

Hi @mashaalmemon,

I believe I need some help.
I had a webpack config with HMR which worked with the webpack-dev-server.
Now I want to bundle it with hapi, so I found your neat plugin. And integration went pretty easy, with the exception that HMR doesn't work for now :(

I register the plugin via Glue, and it looks as simple as:

{
    plugin: {
        register: 'hapi-webpack-plugin',
        options: 'webpack.config.js'
    }
}

While in my webpack config I have the next:

entry: {
        app: [
            'react-hot-loader/patch',
            // activate HMR for React
            'webpack-dev-server/client?reload=true',
            //bundle the client for hot reloading
            //only- means to only hot reload for successful updates
            './app/client/index.js']
    }

So on the load everything works fine, but in the Chrome console I see that any attempt to know if something we updated hits the 404:
image

I also tried to use blipp in order to check if some routes were registered, but no - I do not see any.

I use webpack 2.

Would be very happy to know your thoughts, in which direction I should look.

Regards,

How do I prevent hot-update.json/js files from crowding my project directory

image

webpack config

var ExtractTextPlugin = require('extract-text-webpack-plugin');
var path = require('path');
var webpack = require('webpack');

var sassLoaders = [
  'css-loader',
  'autoprefixer-loader?browsers=last 2 version',
  'sass-loader?includePathes[]=' + path.resolve(__dirname, "./frontend/sass")
];

module.exports = {
  devtool: 'cheap-module-eval-source-map',
  entry: [
    'webpack-hot-middleware/client',
    './frontend/js/entry.cjsx'
  ],
  output: {
    path: __dirname,
    filename: 'public/js/[name].js'
  },
  module: {
    loaders: [
     { test: /\.css$/, loaders: ['style', 'css']},
     { test: /\.cjsx$/, loaders: ['react-hot', 'coffee', 'cjsx']},
     { test: /\.coffee$/, loader: 'coffee' },
     { test: /\.scss$/, loader: ExtractTextPlugin.extract('style-loader', sassLoaders.join('!'))}
    ]
  },
  plugins: [
    new ExtractTextPlugin('public/css/[name].css'),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.NoErrorsPlugin()
  ],
  hot: { },
  resolve: {
    extensions: ['','.js','.sass'],
    modulesDirectories: ['node_modules']
  }
};

server.coffee

WebpackPlugin = require 'hapi-webpack-plugin'
Webpack = require 'webpack'
webpackConfig = require('../webpack.config.js')
...
server.register
  register: WebpackPlugin
  options:
    compiler: new Webpack(webpackConfig)
    assets: {}
    hot: {}
, ->

Respecting vhost option at plugin registration. {options: {routes: {vhost: ''}}

Hi @SimonDegraeve,

Thanks for accepting my pull request for Webpack 2.

I have a use case where my app has different applications (admin area, client area, etc.) which are each separate webpack bundles themselves. Each of these applications actually are served up in my setup on different vhosts (http://admin.mydomain.com, http:, client.mydomain.com) etc. The way the plugin is incorporated into the hapi framwork it doesn't allow this.

However when registering a plugin via server register, options.routes.vhost is an option that can be set as per the hapi API. I'd like to have the plugin respect this option when passed in and only execute the plugin for requests to the vhost vs to any request (which is what happens now)

I am soon to submit another pull request into the codebase that allows one to take advantage of vhosts for the plugin, and have multiple hapi-webpack-plugin's running, each one serving up a unique webpack bundle on a different vhost.

Note, i'm working to ensure it isn't a breaking revision; that is, if the vhost option is not set, it will behave just as it did before. Hopefully you'll be able to accept that pull request into the codebase as well.

I shall reference this issue within the pull request when it's ready.

React hot reloader example

Could you please provide either a react-hot-loader or react-transform example? I haven't been able to get those working with this plugin.

Custom path with React router returns 404

Hi! First, thanks for the plugin!

The plugin works fine by delivering the index.html at /. However, there's a problem when you are trying to access another route, e.g. /customRoute. This can be solved by adding another custom hook in hapi check if the response status is 404, and deliver the index.html page again.

My question is: is there any official way of handling this situation?

Thanks.

Support for Webpack 2

The current version of the plugin doesn't seem to be supporting Webpack 2. Is this on Roadmap?

Compiler Error

Getting a strange error

/PathToProject/node_modules/hapi-webpack-plugin/node_modules/webpack-dev-middleware/middleware.js:32
    var fs = compiler.outputFileSystem = new MemoryFileSystem();
                                       ^

TypeError: Cannot set property 'outputFileSystem' of undefined
    at module.exports (/PathToProject/node_modules/hapi-webpack-plugin/node_modules/webpack-dev-middleware/middleware.js:32:37)
    at Object.register (/PathToProject/node_modules/hapi-webpack-plugin/lib/index.js:53:68)
    at Object.target [as register] (/PathToProject/node_modules/hapi/node_modules/joi/lib/object.js:79:30)
    at Items.serial.self.root._registring (/PathToProject/node_modules/hapi/lib/plugin.js:317:14)
    at iterate (/PathToProject/node_modules/hapi/node_modules/items/lib/index.js:35:13)
    at done (/PathToProject/node_modules/hapi/node_modules/items/lib/index.js:27:25)
    at Object.exports.register (/PathToProject/node_modules/inert/lib/index.js:31:12)
    at Object.target [as register] (/PathToProject/node_modules/hapi/node_modules/joi/lib/object.js:79:30)
    at Items.serial.self.root._registring (/PathToProject/node_modules/hapi/lib/plugin.js:317:14)
    at iterate (/PathToProject/node_modules/hapi/node_modules/items/lib/index.js:35:13)
    at done (/PathToProject/node_modules/hapi/node_modules/items/lib/index.js:27:25)
    at Object.exports.register (/PathToProject/node_modules/vision/lib/index.js:58:12)
    at Object.target [as register] (/PathToProject/node_modules/hapi/node_modules/joi/lib/object.js:79:30)
    at Items.serial.self.root._registring (/PathToProject/node_modules/hapi/lib/plugin.js:317:14)
    at iterate (/PathToProject/node_modules/hapi/node_modules/items/lib/index.js:35:13)
    at Object.exports.serial (/PathToProject/node_modules/hapi/node_modules/items/lib/index.js:38:9)
21 Oct 16:55:04 - [nodemon] app crashed - waiting for file changes before starting...

Running this on:

"dependencies": {
    "breakpoint-sass": "^2.6.1",
    "btns": "^1.1.0",
    "classnames": "^2.2.0",
    "dateformat": "^1.0.11",
    "falcor": "^0.1.13",
    "falcor-hapi": "0.0.2",
    "flux": "^2.1.1",
    "hapi": "^11.0.1",
    "hapi-react": "^3.1.2",
    "hapi-react-views": "^3.1.3",
    "joi": "^6.9.1",
    "lodash": "^3.10.1",
    "mongoose": "^4.1.12",
    "normalize.css": "^3.0.3",
    "object-assign": "^4.0.1",
    "qs": "^5.2.0",
    "react": "^0.13.0",
    "react-picture": "0.0.4",
    "react-slick": "^0.8.1",
    "slick-carousel": "^1.5.8",
    "superagent": "^1.4.0",
    "susy": "^2.2.6",
    "vision": "^3.0.0"
    "autoprefixer": "^6.0.3",
    "babel-core": "^5.8.25",
    "babel-eslint": "^4.1.3",
    "babel-loader": "^5.3.2",
    "babel-plugin-rewire": "^0.1.22",
    "babel-plugin-typecheck": "^1.3.0",
    "babel-runtime": "^5.8.25",
    "command-line-args": "^2.0.2",
    "concurrently": "^0.1.1",
    "css-loader": "^0.20.2",
    "csslint": "^0.10.0",
    "csslint-loader": "^0.2.1",
    "eslint": "^1.7.3",
    "eslint-loader": "^1.1.0",
    "extract-text-webpack-plugin": "^0.8.2",
    "file-loader": "^0.8.4",
    "hapi-cors-headers": "^1.0.0",
    "hapi-webpack-plugin": "^1.1.0",
    "html-loader": "^0.3.0",
    "html-webpack-plugin": "^1.6.2",
    "inert": "^3.1.0",
    "json-loader": "^0.5.3",
    "jsx-loader": "^0.13.2",
    "node-sass": "^3.3.3",
    "nodemon": "^1.7.3",
    "opn": "^3.0.2",
    "postcss-loader": "^0.7.0",
    "react-hot-loader": "^1.3.0",
    "sass-loader": "^3.0.0",
    "style-loader": "^0.13.0",
    "ts-loader": "^0.5.6",
    "typescript": "^1.6.2",
    "webpack": "^1.12.2",
    "webpack-dev-server": "^1.12.1",
    "webpack-error-notification": "^0.1.4"
  }

Example with route.handler replying file

Hi @SimonDegraeve ,
How can I use this plugin when my route replies a file?
It seems to not recognize the injected bundled file using:
assuming you've registered a view plugin such as Inert/Views -

<some route>...
handler: function(req, rep) {
  return rep.file('index.html')
}

It seems to return the html without the resolved bundled file.

Move babel-polyfill to dependencies

You're importing babel-polyfill in your codebase, but it's listed under devDependencies. Error occurs unless user has babel-polyfill already installed.

EDIT: It would be better to use transform-runtime instead for reasons here as well as avoiding conflicts with existing codebases that use babel-polyfill. I'm having an issue as I'm using babel v7.

Polling Issue Question

Been battling with this for a while and not sure where to post this. I'm using Hapi 9 and hooking up the webpack plugin and not getting any HMR action. I see a polling error in the browser console:

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (socket.io, line 0)
http://localhost:8000/socket.io/?EIO=3&transport=polling&t=1441832575608-122

But I get;

[Log] [HMR] Waiting for update signal from WDS...

in the console. When I load the Webpack Dev server and point to the same config, HMR works. I'm rendering a jsx on the server side in a views folder in lieu of an index html, which then pulls in the client side React code that should be hot reloading.

server.js

// Bundle the client assets with Webpack
//var StartWebpack = require('./webpack');
//StartWebpack();

// Create a basic Hapi.js server
var Hapi = require('hapi');
var dateFormat = require('dateformat');
var format = "dd mmm HH:MM:ss";



// Basic Hapi.js connection stuff
var server = new Hapi.Server();
server.connection({
  host: 'localhost',
  port: 8000
});


var rootHandler = function (request, reply) {
    reply.view('Default');
};

server.register([
      require('vision'),
      require('inert'),
      {
        register : require('hapi-webpack-plugin'),
        options : './webpack.hot.config.js'
      }
    ], function (err) {

    server.views({
        engines: {
            jsx: require('hapi-react-views')
        },
        relativeTo: __dirname,
        path: 'views'
    });


    // Add a route to serve static assets (CSS, JS, IMG)
    server.route({
      method: 'GET',
      path: '/{param*}',
      handler: {
        directory: {
          path: 'build'
        }
      }
    });

    // Add main app route
    server.route({
      method: 'GET',
      path: '/',
      handler: rootHandler
    });


    server.start(function() {
      console.info('==> '+ dateFormat(new Date(), format));
      console.info("==> โœ…  Server is listening");
      console.info("==> ๐ŸŒŽ  Go to " + server.info.uri.toLowerCase());
    });
});

webpack.hot.config.js

var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

var pkg = require('./package.json');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var autoprefixer = require('autoprefixer-core');
var util = require('util');
var webpack = require('webpack');


var DEBUG = process.env.NODE_ENV === 'development';
var TEST = process.env.NODE_ENV === 'test';

var cssBundle = path.join('css', util.format('app.%s.css', pkg.version));
var jsBundle = path.join('js', util.format('app.%s.js', pkg.version));

var jsxLoader;
var sassLoader;
var cssLoader;
var fileLoader = 'file-loader?name=[path][name].[ext]';
var htmlLoader = [
    'file-loader?name=[path][name].[ext]',
    'template-html-loader?' + [
        'raw=true',
        'engine=lodash',
        'version=' + pkg.version,
        'title=' + pkg.name,
        'debug=' + DEBUG
    ].join('&')
].join('!');
var jsonLoader = ['json-loader'];

var sassParams = [
    'outputStyle=expanded',
    'includePaths[]=' + path.resolve(__dirname, './app/scss'),
    'includePaths[]=' + path.resolve(__dirname, './node_modules')
];

jsxLoader = [];
jsxLoader.push('react-hot');
jsxLoader.push('babel-loader?optional[]=runtime&stage=0&plugins=rewire');
sassParams.push('sourceMap', 'sourceMapContents=true');
sassLoader = [
    'style-loader',
    'css-loader?sourceMap&modules&localIdentName=[name]__[local]___[hash:base64:5]',
    'postcss-loader',
    'sass-loader?' + sassParams.join('&')
].join('!');
cssLoader = [
    'style-loader',
    'css-loader?sourceMap&modules&localIdentName=[name]__[local]___[hash:base64:5]',
    'postcss-loader',
    'csslint'
].join('!');


module.exports = {
    devtool: 'eval',
    context: path.join(__dirname, './app'),
    entry: [
        'webpack-dev-server/client?http://localhost:8000',
        'webpack/hot/only-dev-server',
        path.resolve(__dirname, './views/Default'),
        path.resolve(__dirname, './app/app.jsx')
    ],/*
    output: {
        path: path.resolve(__dirname, 'hot'),
        filename: 'bundle.js'
    },*/
    output: {
        path: path.resolve(pkg.config.buildDir),
        filename: jsBundle
    },
    plugins: [
        new ExtractTextPlugin(cssBundle, {
            allChunks: true
        }),
        new webpack.optimize.DedupePlugin(),
        new webpack.HotModuleReplacementPlugin()
    ],
    resolve: {
        extensions: ['', '.js', '.json', '.jsx']
    },
    module: {
        loaders: [{
            test: /\.html$/,
            loader: htmlLoader
        }, {
            test: /\.css$/,
            loader: 'style!css'
        }, {
            test: /\.scss$/,
            loader: sassLoader
        }, {
            test: /\.jpe?g$|\.gif$|\.png$|\.ico|\.svg$|\.woff$|\.ttf$|\.eot$/,
            loader: fileLoader
        }, {
            test: /\.json$/,
            exclude: /node_modules/,
            loaders: jsonLoader
        }, {
            test: /\.jsx$/,
            loaders: jsxLoader,
            exclude: /node_modules/
        }, {
            include: /\.js$/,
            loaders: ["babel-loader?stage=0&optional=runtime&plugins=typecheck"],
            exclude: /node_modules/
        }]
    }
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.