Giter Site home page Giter Site logo

webpack-hot-middleware's Introduction

Webpack Hot Middleware

Webpack hot reloading using only webpack-dev-middleware. This allows you to add hot reloading into an existing server without webpack-dev-server.

This module is only concerned with the mechanisms to connect a browser client to a webpack server & receive updates. It will subscribe to changes from the server and execute those changes using webpack's HMR API. Actually making your application capable of using hot reloading to make seamless changes is out of scope, and usually handled by another library.

If you're using React then some common options are react-transform-hmr and react-hot-loader.

npm version CircleCIcodecovMIT Licensed

Installation & Usage

See example/ for an example of usage.

First, install the npm module.

npm install --save-dev webpack-hot-middleware

Next, enable hot reloading in your webpack config:

  1. Add the following plugins to the plugins array:

    plugins: [
        new webpack.HotModuleReplacementPlugin(),
    ]

    Occurence ensures consistent build hashes, hot module replacement is somewhat self-explanatory, no errors is used to handle errors more cleanly.

  2. Add 'webpack-hot-middleware/client' into an array of the entry object. For example:

    entry: {
        main: ['webpack-hot-middleware/client', './src/main.js']
    }

    This connects to the server to receive notifications when the bundle rebuilds and then updates your client bundle accordingly.

Now add the middleware into your server:

  1. Add webpack-dev-middleware the usual way

    var webpack = require('webpack');
    var webpackConfig = require('./webpack.config');
    var compiler = webpack(webpackConfig);
    
    app.use(require("webpack-dev-middleware")(compiler, {
        /* Options */
    }));
  2. Add webpack-hot-middleware attached to the same compiler instance

    app.use(require("webpack-hot-middleware")(compiler));

And you're all set!

Changelog

2.0.0

Breaking Change

As of version 2.0.0, all client functionality has been rolled into this module. This means that you should remove any reference to webpack/hot/dev-server or webpack/hot/only-dev-server from your webpack config. Instead, use the reload config option to control this behaviour.

This was done to allow full control over the client receiving updates, which is now able to output full module names in the console when applying changes.

Documentation

More to come soon, you'll have to mostly rely on the example for now.

Config

Client

Configuration options can be passed to the client by adding querystring parameters to the path in the webpack config.

'webpack-hot-middleware/client?path=/__what&timeout=2000&overlay=false'
  • path - The path which the middleware is serving the event stream on
  • name - Bundle name, specifically for multi-compiler mode
  • timeout - The time to wait after a disconnection before attempting to reconnect
  • overlay - Set to false to disable the DOM-based client-side overlay.
  • reload - Set to true to auto-reload the page when webpack gets stuck.
  • noInfo - Set to true to disable informational console logging.
  • quiet - Set to true to disable all console logging.
  • dynamicPublicPath - Set to true to use webpack publicPath as prefix of path. (We can set __webpack_public_path__ dynamically at runtime in the entry point, see note of output.publicPath)
  • autoConnect - Set to false to use to prevent a connection being automatically opened from the client to the webpack back-end - ideal if you need to modify the options using the setOptionsAndConnect function
  • ansiColors - An object to customize the client overlay colors as mentioned in the ansi-html-community package.
  • overlayStyles - An object to let you override or add new inline styles to the client overlay div.
  • overlayWarnings - Set to true to enable client overlay on warnings in addition to errors.
  • statsOptions - An object to customize stats options.

Note: Since the ansiColors and overlayStyles options are passed via query string, you'll need to uri encode your stringified options like below:

var ansiColors = {
  red: '00FF00' // note the lack of "#"
};
var overlayStyles = {
  color: '#FF0000' // note the inclusion of "#" (these options would be the equivalent of div.style[option] = value)
};
var hotMiddlewareScript = 'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000&reload=true&ansiColors=' + encodeURIComponent(JSON.stringify(ansiColors)) + '&overlayStyles=' + encodeURIComponent(JSON.stringify(overlayStyles));

Middleware

Configuration options can be passed to the middleware by passing a second argument.

app.use(require("webpack-hot-middleware")(compiler, {
    log: false,
    path: "/__what",
    heartbeat: 2000
}));
  • log - A function used to log lines, pass false to disable. Defaults to console.log
  • path - The path which the middleware will serve the event stream on, must match the client setting
  • heartbeat - How often to send heartbeat updates to the client to keep the connection alive. Should be less than the client's timeout setting - usually set to half its value.

How it Works

The middleware installs itself as a webpack plugin, and listens for compiler events.

Each connected client gets a Server Sent Events connection, the server will publish notifications to connected clients on compiler events.

When the client receives a message, it will check to see if the local code is up to date. If it isn't up to date, it will trigger webpack hot module reloading.

Multi-compiler mode

If you're using multi-compiler mode (exporting an array of config in webpack.config.js), set name parameters to make sure bundles don't process each other's updates. For example:

// webpack.config.js
module.exports = [
    {
        name: 'mobile',
        entry: {
            vendor: 'vendor.js',
            main: ['webpack-hot-middleware/client?name=mobile', 'mobile.js']
        }
    },
    {
        name: 'desktop',
        entry: {
            vendor: 'vendor.js',
            main: ['webpack-hot-middleware/client?name=desktop', 'desktop.js']
        }
    }
]

Other Frameworks

Hapi

Use the hapi-webpack-plugin.

Koa

koa-webpack-middleware wraps this module for use with Koa 1.x

koa-webpack can be used for Koa 2.x

Troubleshooting

Use on browsers without EventSource

If you want to use this module with browsers that don't support eventsource, you'll need to use a polyfill. See issue #11

Not receiving updates in client when using Gzip

This is because gzip generally buffers the response, but the Server Sent Events event-stream expects to be able to send data to the client immediately. You should make sure gzipping isn't being applied to the event-stream. See issue #10.

Use with auto-restarting servers

This module expects to remain running while you make changes to your webpack bundle, if you use a process manager like nodemon then you will likely see very slow changes on the client side. If you want to reload the server component, either use a separate process, or find a way to reload your server routes without restarting the whole process. See https://github.com/glenjamin/ultimate-hot-reloading-example for an example of one way to do this.

Use with multiple entry points in webpack

If you want to use multiple entry points in your webpack config you need to include the hot middleware client in each entry point. This ensures that each entry point file knows how to handle hot updates. See the examples folder README for an example.

entry: {
    vendor: ['jquery', 'webpack-hot-middleware/client'],
    index: ['./src/index', 'webpack-hot-middleware/client']
}

License

See LICENSE file.

webpack-hot-middleware's People

Contributors

aetherall avatar alexander-akait avatar arunoda avatar benjarwar avatar chiplay avatar danro avatar dependabot[bot] avatar eokoneyo avatar glenjamin avatar gravityrail avatar jbarrus avatar joshwiens avatar martinmunillas avatar martwana avatar mistic avatar mohsen1 avatar nttibbetts avatar nvdlug avatar okcoker avatar pd4d10 avatar piperchester avatar restuta avatar richardgoater avatar richardscarrott avatar rmarscher avatar rossipedia avatar runrioter avatar superoleg39 avatar yyx990803 avatar zdend 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  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  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

webpack-hot-middleware's Issues

Error: Aborted because ... is not accepted

When trying to hot-update React components with webpack-hot-middleware, I receive the following error every time:

Uncaught (in promise) Error: Aborted because ./SomeComponent.js is not accepted

I'm not exactly sure why that happens... But I've noticed that:

I can hot-update anything else (manually replacing my redux-reducer using module.hot.accept, reload css using style-loader, etc.).

Stepping through with the debugger, I can see that in file process-update.js line 32, The callback function given to module.hot.check is never called. It seems the hotCheck() function assigns its apply parameter (the callback) to a global hotApplyOnUpdate. This function is then given to hotApply() which expects to receive an options object, and not a callback.

Searching for all usages of hotApplyOnUpdate yields:

  • Initially defined as true;
  • Assigned to be the given apply parameter every time hotCheck() is called.
  • Given as an argument to hotApply() inside hotUpdateDownloaded().

So, is it a problem with webpack's HMR plugin?


I'm using:

Nicer looking overlay

If anyone wants to me the error overlay neater, or add visual feedback for success similarly to figwheel - please go ahead and submit a PR

Feature request: Expose an event handler so server can tell client to reload

Thanks for your ultimate-hot-reloading-example repo. I've got another request here. When I update the routes on the server side, it would be nice if the server could send an event to the client in order to tell it to automatically reload. I realize this doesn't necessarily belong in this project but you've already got the event stuff set up here so I figure it makes sense to put something like that here. What do you think?

Windows: [HMR] The following modules couldn't be hot updated: (Full reload needed)

I'm trying to get hot reloading working on Windows (node 0.12.2 / node 5.0.0). Hot Reloading works fine when the code is ran with Mac OSX (node 0.12.4).

I see the following output in various browsers on windows:

[HMR] connected bundle.js:61752:23
[HMR] bundle rebuilding bundle.js:61805:23
[HMR] bundle rebuilt in 1217ms bundle.js:61807:23
[HMR] Checking for updates on the server... bundle.js:61884:23
GET XHR http://localhost:3000/static/40c9217ec465f79054a8.hot-update.json [HTTP/1.1 200 OK 8ms]
GET http://localhost:3000/static/0.40c9217ec465f79054a8.hot-update.js [HTTP/1.1 200 OK 1ms]
[HMR] The following modules couldn't be hot updated: (Full reload needed) bundle.js:61918:1
[HMR]  - ./common/components/Dashboard.js bundle.js:61923:12
[HMR] Reloading page

As already mentioned, everything works fine on OSX.

webpack.config.js
server.js

The project is rendering a React + Redux app serverside.

Before connecting to HMR, I get a Ract warning, which I don't think is connected to the issue and is caused by using some Redux Devtools. But better make sure:

Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
 (client) id=".1yovdae1q0w.0">Dashboard12312</div>
 (server) id=".1yovdae1q0w.0">404</div><div style=

iss1
iss2
iss3

Add a note about gzip being incompatible with HMR

If webpack-hot-middleware is installed after gzip middleware (like compression), no events will be sent as the buffers are not properly flushed.

This took a while to track down so it would be great if it were documented.

Alternatively, we can check for the existence of a res.flush() method and call it. This would make SSE work even if gzip is used. See expressjs/compression#17

Can anyone help with this error?

> node server.js "-verbose"

App listening at http://localhost:3000
webpack built ac8a8b580e676d49a82f in 194ms
Hash: ac8a8b580e676d49a82f
Version: webpack 1.12.9
Time: 194ms
    Asset     Size  Chunks       Chunk Names
bundle.js  45.3 kB       0       main
chunk    {0} bundle.js (main) 7.79 kB [rendered]
    [0] multi main 40 bytes {0} [built] [1 error]
    [1] (webpack)-hot-middleware/client-overlay.js 1.01 kB {0} [built]
    [2] (webpack)-hot-middleware/client.js 3.24 kB {0} [built]
    [3] (webpack)-hot-middleware/~/ansi-regex/index.js 145 bytes {0} [built]
    [4] (webpack)-hot-middleware/~/strip-ansi/index.js 161 bytes {0} [built]
    [5] (webpack)-hot-middleware/process-update.js 2.95 kB {0} [built]
    [6] (webpack)/buildin/module.js 251 bytes {0} [built]

ERROR in multi main
Module not found: Error: Cannot resolve module 'react-hot' in /Users/terry/Desktop/Projects/react-hmre-test
 @ multi main
webpack: bundle is now VALID.

I honestly don't know how to diagnose this. Still learning Webpack & all these plugins. Any info would be appreciated. I read the answer to this question in the FAQ, didn't get me anywhere.

Relay GraphQL Support needed

Hello
It would be great if the hot-middleware could update a component when its Relay GraphQL Query changes. At the moment it is not aware of it and forces the developer to manually do a full page reload which destroys his current application state.

In this example

import React from 'react';
import Relay from 'react-relay';

/**
 * The Home component.
 */
class Home extends React.Component {
  // Expected properties.
  static propTypes = {
    viewer: React.PropTypes.object.isRequired
  };
  // Initialize the component.
  constructor(props) {
    super(props);
  }
  // Render the component.
  render() {
    // Return the component UI.
    return (
      <div>
        <h1>Widget list</h1>
        <ul>
          {this.props.viewer.widgets.edges.map(edge =>
              <li key={edge.node.id}>{edge.node.name} (ID: {edge.node.id})</li>
          )}
        </ul>
      </div>
    );
  }
}

/**
 * The home data container.
 */
export default Relay.createContainer(Home, {
  fragments: {
    viewer: () => Relay.QL`
      fragment on User {
        widgets(first: 5) {
          edges {
            node {
              id,
              name,
            },
          },
        },
      }
    `
  }
});

We should be able to make a change to the Query and the hot-middleware should update the component.

Hope it will be easy for you to add this feature - it would improve React development hugely.

Thank you

Missing 3000 port in requests

I tried to run https://github.com/gaearon/react-transform-boilerplate serving index.html from another server by adding <script src="http://localhost:3000/bundle.js"></script> in the index.html file.
The request made to webpack-dev-server is without port : http://localhost/__webpack_hmr.

I tried adding path in webpack config replacing "webpack-hot-middleware/client" by "webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr".

It almost worked and now I can see [HMR] connected in the console. But I've got the following error when updating a component (for example):
But I've got a 404 for http://localhost/ee5f8b082a1e37a8b436.hot-update.json
The port 3000 is missing.

The following modules couldn't be hot updated: (Full reload needed)

hi, I am trying to use your plugin with my express server. the thing is that, the server runs, but I can't get it to reload my stuff.


EDIT

I added '?reload=true' in the entry and now it reloads. is this the intended behavior? with this option actually the browser is refreshed but I lose state


I keep getting this warning message in the chrome devtools:

[HMR] The following modules couldn't be hot updated: (Full reload needed)
process-update.js?e13e:64 [HMR]  - ./client/index.js

Here is everything needed to simulate the error (hopefully) with the same code I am using.

package.json

{
  "name": "hot",
  "version": "1.0.0",
  "description": "",
  "dependencies": {
    "express": "^4.13.4",
    "webpack": "^1.12.12",
    "webpack-dev-middleware": "^1.5.1",
    "webpack-hot-middleware": "^2.6.2"
  },
  "devDependencies": {
    "babel-core": "^6.4.5",
    "babel-loader": "^6.2.1",
    "babel-preset-es2015": "^6.3.13",
    "nodemon": "^1.8.1"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "./node_modules/.bin/nodemon server/app.js"
  },
  "author": "",
  "license": "MIT",
  "private": true
}

webpack.config.js

var webpack = require('webpack');

module.exports = {
  devtool: '#eval-source-map',
  entry: [
    'webpack-hot-middleware/client',
    __dirname + '/client/index.js'
  ],
  output: {
    path: '/',
    filename: 'bundle.js',
    publicPath: 'http://localhost:3000/scripts/'
  },
  module: {
    loaders: [{
      test: /\.js$/,
      loader: 'babel',
      exclude: /(node_modules)/,
      query: {
        presets: ['es2015']
      }
    }]
  },
  resolve: {
    root: process.cwd(),
    modulesDirectories: ['node_modules'],
    extensions: ['', '.js']
  },
  plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ],
  target: 'web'
};

server/app.js

var path = require('path');
var express = require('express');
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var webpackConfig = require('../webpack.config');
var app = express();
var router = express.Router();
var compiler = webpack(webpackConfig);
var root = path.resolve(__dirname, '../client');
var index = path.join(root, 'index.html');

app.use(webpackDevMiddleware(compiler, {
  publicPath: webpackConfig.output.publicPath,
  stats: {
    colors: true
  }
}));

app.use(webpackHotMiddleware(compiler, {
  log: console.log
}));

router.get('/', (req, res) => res.sendFile(index))

app.use(router);
app.listen(3000, () => console.log('listening on 3000'))

client/index.html

<!doctype html>
<script src="/scripts/bundle.js"></script>

client/index.js

console.log('something');

nodemon.json

{
  "ignore": "client/**/*"
}
$ npm install
$ npm start

This example https://github.com/madole/webpack-dev-middleware-boilerplate which is very similar works correctly, however is using [email protected]

Safari 9 requires polyfill?

Just noticed that the following warning pops up in Safari 9:
[Warning] webpack-hot-middleware's client requires EventSource to work. You should include a polyfill if you want to support this browser: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events#Tools

According to w3c spec eventsource interface need to have a constructor but it doesn't necessary need to be a function.
It is an object in Safari 9 with following properties

EventSourceConstructor = $1
CLOSED: 2
CONNECTING: 0
OPEN: 1
length: 1
prototype: EventSourcePrototype {URL: undefined, url: undefined, withCredentials: undefined, readyState: undefined, …}
Object Prototype

Is there any reason why not to just check for window.EventSource !== undefined instead of requiring EventSource to be function?

Build breaks after update 2.5.1 -> 2.6.0

See the offending pull request.

/home/ubuntu/react-pure-component-starter/node_modules/babel/lib/_babel-node.js:63
babel.register({
      ^
TypeError: Object #<Object> has no method 'register'
    at Object.<anonymous> (/home/ubuntu/react-pure-component-starter/node_modules/babel/lib/_babel-node.js:63:7)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3
npm ERR! Test failed.  See above for more details.

Proxying existing vhost

I'm trying to proxy a vhost through whm and I am getting errors about Access-Control-Allow-Origin on hot-update.json. Found this issue on react-hot-loader. Is there something I need to add to the whm entry?

entry: [
    'webpack/hot/dev-server',
    'webpack-hot-middleware/client?path=http://mywebsite.dev',
    './src/js/entries/app.jsx'
],

Can't connect the stream

@glenjamin I wonder why I keep getting GET /__webpack_hmr I feel like this is because I'm using react-router (on the client) but can't figure out why webpack-hot-middleware won't find the correct path (I tried set the path as well).

Part of the config on the server.js

if (app.get('env') === 'development') {

  //
  // Webpack dev env setup
  //
  let webpack = require('webpack');
  let webpackConfig = require('./webpack.dev');
  let compiler = webpack(webpackConfig);

  app.use(require("webpack-dev-middleware")(compiler, {
    publicPath: webpackConfig.output.publicPath,
    noInfo: true
  }));

  app.use(require("webpack-hot-middleware")(compiler));

  //
  // Express dev env setup
  //
  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: err
    });
  });
}

webpack.dev.js

'use strict';

let path = require('path');
let webpack = require('webpack');

module.exports = {
  // sourcemap support
  devtool: 'inline-source-map',
  entry: [
    'webpack-hot-middleware/client',
    path.join(__dirname, './public/javascripts/routes.jsx')
  ],
  output: {
    path: path.join(__dirname, './public/build/javascripts'),
    filename: 'bundle.js',
    publicPath: '/'
  },
  module: {
    loaders: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: 'babel-loader'
      }
    ]
  },
  resolve: {
    // add shortcut as alias
    alias: {
      '@components': path.join(__dirname, 'public/javascripts/components'),
      '@javascripts': path.join(__dirname, 'public/javascripts')
    },
    // extensions listed here can be omitted in `import`s
    extensions: ['', '.js', '.jsx'],
    // directories which are searched implicitly in `import`s
    modulesDirectories: ['node_modules', 'components', 'vendors']
  },
  plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ]
};

Changes not being made on the server side.

Hello, I have been trying to set up webpack-hot-middleware along with webpack-dev-middleware on hapi. I am using hapi and reactjs. Everything seems to go fine when making changes to my files. They get reloaded on the client and webpack rebundles the changed files on the server as well; however, when I reload the page, react complains that the code in the client is different from that on the server. Meaning that, the code on the client was updated but the code on the server was not.

Isn't webpack-hot-middleware supposed to help me to do this or am I wrong?

The path in middleware options doesn't change path in client's options.

In order to use middleware in context path /desk I need to set options in that manner:

app.use(webpackHotMiddleware(compiler, {
    log: console.log, path: '/desk/__webpack_hmr', heartbeat: 10 * 1000
}));

But client still try to connect to /__webpack_hmr

Changing hardcoded value in client.js to the proper one removed the error.

var options = {
  path: "/desk/__webpack_hmr",
  timeout: 20 * 1000,
  overlay: true,
  reload: false
};

Could this setting be translated to client somehow ?

Getting a ton of builds triggering

Not sure if this is just a logging issue or if it is actually compiling the bundle a bunch of times over again, but either way, my screen gets flooded with these messages:

    app: [2:20:52 AM] [webpack] ✗ build is now INVALID
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: webpack building...
    app: [2:21:01 AM] [webpack] ✓ build is now VALID
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms
    app: webpack built a09e4a45b50b0187693b in 8842ms

EventSource vs Websockets?

Just wondering the reason for using EventSource over Websockets? I have found that chrome and firefox have differing implementations of EventSource. The spec seems to have been abandoned as well.

Skip this middleware when executing bundle on server?

Maybe I'm going about this all wrong but I can't seem to find a working solution/boilerplate/example that does exactly what I want.

I'm trying to put together a clean and simple dev server for universal/isomorphic React apps which supports both server rendering and hot reloading at the same time. I was originally using the transpiled lib for the server (without hot reloading) and a bundle for the client (with hot reloading) but React didn't like that for some reason. So what I'm trying to do now is use a single bundle with hot reloading enabled, and the server will use that for its own rendering, but since this middleware is designed for the browser, the server has problems executing the bundle.

How feasible would it be to add some logic that skips all the hot reloading functionality when run on the server?

Actually, ideally, the server would get the hot reloads as well, which would avoid having to restart it after changes each time we want to test server rendering and would also allow stuff like bundled universal API functionality to be hot reloaded. But one step at a time I suppose. :)

Doesn't work when building multiple webpacks

TypeError: Cannot read property 'forEach' of undefined
at buildModuleMap (/my_server/node_modules/webpack-hot-middleware/middleware.js:73:10)

You can export an array of webpack configs rather than just a single one. I am currently doing this in an isomorphic app which has a normal bundle for the client and then a second bundle to do server-side rendering.

The stats returned from the webpack compiler plugin might have an array of "children" to look in rather than a top-level "modules".

Should handle when app server is reloaded via nodemon

I have it so that my app server (which, of course, contains webpack-dev-middleware and webpack-hot-middleware) is restarted when any server-side files are changed. Unfortunately, what's happening is that as soon as the server is restarted, something is triggered such that now I see the following message in the browser console:

GET http://localhost:3000/__webpack_hmr net::ERR_INCOMPLETE_CHUNKED_ENCODING

I don't know enough to know why this is happening exactly, but I do know that I'd like the page to reload when this happens. Any idea on how to do this?

Koa middleware

Is there a plan to support koa server? I would write the middleware myself, but I would not know where to start. If someone could at least point me into the right direction ...

2.7.0 Broke integration with html-webpack-plugin (probably)

Hello. Have strange issue with new build

After upgrade to 2.7.0 result of bundling (in console):
webpack built html-webpack-plugin for "index.html" undefined in undefinedms
WIth 2.6.4 it was something like:
webpack built fc2ee45ece47dfbfa022 in 57003ms

But it's not the worst. Worst is that HMR broken. Simple change in source leading to

[HMR] Cannot find update (Full reload needed)
[HMR] (Probably because of restarting the server)

in browser console.

Can provide any additional information if needed.

Thanks in advance and sorry for my English

Middleware fails to respond to GET /**/*.hot-update.json

my console gets:

GET http://localhost:8080/some/path/i/have/04695a7493d5bc4d778f.hot-update.json 
404 (Not Found)

it seems that instead of GET /04695a7493d5bc4d778f.hot-update.json, hot-middleware GETs my/path/to/somewhere/04695a7493d5bc4d778f.hot-update.json which is not caught by the middleware.

Cannot read property 'children' of undefined in hot update

Not sure if this is to do with a patch to the source map functionality in Babel that I made, but reporting it because the code seems like it'd benefit from a consistency check anyway.

Generated hot update, lines 419-430:

        // remove outdated dependency from module children
        for(var moduleId in outdatedDependencies) {
            if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
                var module = installedModules[moduleId]; // undefined var <----------
                var moduleOutdatedDependencies = outdatedDependencies[moduleId];
                for(var j = 0; j < moduleOutdatedDependencies.length; j++) {
                    var dependency = moduleOutdatedDependencies[j];
                    var idx = module.children.indexOf(dependency); //throws here <------
                    if(idx >= 0) module.children.splice(idx, 1);
                }
            }
        }

Maybe make sure that the children are actually children of the module in question? That said, if it's my bad I apologize - trying to patch code generators & updating how we use hot updates with React and Webpack etc etc is pretty labyrinthine, so it's hard to figure out why a particular error was thrown in the first place through 3 or 4 layers of indirect generation.

EventSource Polyfill

Could you include an EventSource polyfill for IE by default, or recommend one and document how to configure it?

I just got one working, but I had to modify middleware.js:

npm install eventsource-polyfill
  entry: [
    'eventsource-polyfill',
    'webpack-hot-middleware/client',
    './app/index.js'
  ],

Then because the polyfill in question tacks on some query parameters:

--- middleware.js
+++ middleware.js
@@ -26,7 +26,7 @@
     });
   });
   return function(req, res, next) {
-    if (req.url !== opts.path) return next();
+    if (req.path !== opts.path) return next();
     eventStream.handler(req, res);
   };
 }

Add an option to control verbosity

Currently it's outputing a lot of messages to my console. Can you add an option, such as the noInfo or quiet in webpack-dev-middleware, so that people can control the verbosity of output?

screen shot 2015-10-02 at 6 06 48 pm

Checking for updates - getting a timeout

image

As the screenshot says, i'm getting a timeout on the request for the manifest.
If i open the request, i get a 302 and the file back.

Using:
Node: v4.1.2
"express": "^4.13.3",
"webpack": "^1.12.2",
"webpack-dev-middleware": "^1.2.0",
"webpack-hot-middleware": "^2.4.1"

For user not using express

If i'm not using any framework like express,how to change this two line?thanks

app.use(require("webpack-dev-middleware")(compiler, {
    noInfo: true, publicPath: webpackConfig.output.publicPath
}));
app.use(require("webpack-hot-middleware")(compiler));

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.