Do I need a webpack-dev server if I use a node server like express

I am following some tutorials to create an isomorphic application with expression and responsiveness. I am confused with webpack-dev server.

The webpack tutorial talks about web-package-dev-server:

This connects a small express server to localhost: 8080, which serves your static assets, as well as a package (compiled automatically).

It automatically refreshes the browser page when recompiling the package (socket.io). Open http: // localhost: 8080 / webpack-dev-server / bundle in your browser.

Since I have an express server, do I really need a webpack-dev server? Or what are the advantages and disadvantages of using it? And if I want to use the "hot-loader" mode, do I need a webpack-dev server?

+42
webpack express webpack-dev-server
Oct 28 '15 at 7:32
source share
1 answer

Since I have an express server, do I really need a webpack-dev server?

Yes and no. You can use a hybrid approach that essentially configures the webpack-dev server as a proxy server. You have an express server serving everything except assets. If it is an asset, the request is sent / proxied to the webpack-dev server. See the Answer here for more details: How to allow the webpack-dev server to allow entry points from the responder router

Alternatively, you can use webpack-dev-middleware and webpack-hot-middleware if you do not want to deal with all the dirty proxy logic and have 2 servers. See an example here: https://github.com/glenjamin/webpack-hot-middleware/blob/master/example/server.js

What are the advantages and disadvantages of using it?

Reboot in real time and replace the hot module. A very useful feature for development in my opinion

And if I want to use hot-loader, do I need a webpack-dev server?

No, it runs on top of the Webpack hot module replacement interface . You can create your own hot server if you want. The webpack-dev-server client just listens on socket.io for hot updates and calls postMessage ( https://github.com/webpack/webpack-dev-server/blob/8e8f540b2f7b35f7b6c3ce616a7fd2215aaa6eea/client/index.js#L64- then the server https://github.com/webpack/webpack/blob/bac9b48bfb0f7dd9732f2faafb43ebb22ee2a2a7/hot/only-dev-server.js#L59-L67 is selected.

Or I recommend that you can just use webpack-dev-middleware and webpack-hot-middleware, which I mentioned above. This way you don't have to worry about proxy logic, and you can easily integrate a hot reboot into an existing express server without the need for webpack-dev-server

+53
Oct 28 '15 at 9:11
source share



All Articles