如果我正在使用像express这样的节点服务器,是否需要webpack-dev-server [英] Do I need webpack-dev-server if I am using a node server like express

查看:134
本文介绍了如果我正在使用像express这样的节点服务器,是否需要webpack-dev-server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在跟随一些教程来构建一个具有快速反应的同构应用程序。我对webpack-dev-server感到困惑。

I am following some tutorials to build an isomorphic app with express and react. I am confusing with the webpack-dev-server.

webpack教程讲述了webpack-dev-server:

The webpack tutorial says about the webpack-dev-server:


这将绑定本地主机上的一个小型快速服务器:8080,它为您的静态资产以及捆绑(自动编译)提供服务。

This binds a small express server on localhost:8080 which serves your static assets as well as the bundle (compiled automatically).

当重新编译软件包(socket.io)时,它会自动更新浏览器页面。在浏览器中打开 http:// localhost:8080 / webpack-dev-server / bundle 因为我有快递服务器,我真的需要webpack-dev-server吗?

It automatically updates the browser page when a bundle is recompiled (socket.io). Open http://localhost:8080/webpack-dev-server/bundle in your browser.

或者使用它的优点和缺点是什么?如果我想使用反应热加载器,webpack-dev-server是否需要?

Since I have express server, do I really need webpack-dev-server? Or what's the advantages and disadvantages of using it? And if I want to use react-hot-loader, is the webpack-dev-server necessary?

推荐答案


因为我有快速服务器,我真的需要webpack-dev-server吗?

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

是和否。您可以使用混合方法,其基本上将webpack-dev-server设置为代理。你有你的快递服务器,除了资产以外的所有服务。如果是资产,则请求将转发/代理到webpack-dev-server。有关详细信息,请参阅此处的答案:如何允许webpack-dev-server允许来自反应路由器的入口点

Yes and no. You can use a hybrid approach, which essentially setup the webpack-dev-server as a proxy. You have your express server that serves everything except for assets. If it's an asset, the request gets forwarded/proxied to the webpack-dev-server. See the answer here for more details: How to allow for webpack-dev-server to allow entry points from react-router

或者,您可以使用 webpack-dev-middleware webpack-hot-middleware ,如果你不想处理所有的凌乱的代理逻辑,并有2台服务器运行。请参阅以下示例: https://github.com/ glenjamin / webpack-hot-middleware / blob / master / example / server.js

Alternatively, you can use webpack-dev-middleware and webpack-hot-middleware instead if you don't want to deal with all the messy proxying logic and having 2 servers running. See the example here: https://github.com/glenjamin/webpack-hot-middleware/blob/master/example/server.js


使用的优点和缺点是什么它是吗?

what's the advantages and disadvantages of using it?

实时重新加载和热模块更换。在我看来,非常有用的开发功能

Live-reloading and hot module replacement. Very useful feature for development in my opinion


如果我想使用反应热加载器,webpack-dev-server是否需要?

And if I want to use react-hot-loader, is the webpack-dev-server necessary?

不,它适用于Webpack的热模块更换界面。如果需要,您可以创建自己的热服务器。 webpack-dev-server客户端只需要监听socket.io即可进行热更新,并调用postMessage( https://github.com/webpack/webpack-dev-server/blob/8e8f540b2f7b35f7b6c3ce616a7fd2215aaa6eea/client/index.js#L64-L67 ),然后拿起由服务器 https:// github。 com / webpack / webpack / blob / bac9b48bfb0f7dd9732f2faafb43ebb22ee2a2a7 / hot / only-dev-server.js#L59-L67

Nope, it works on top of Webpack's hot module replacement interface. You can create your own 'hot server' if you want. The webpack-dev-server client just listen to socket.io for hot updates and calls postMessage (https://github.com/webpack/webpack-dev-server/blob/8e8f540b2f7b35f7b6c3ce616a7fd2215aaa6eea/client/index.js#L64-L67) which is then picked up by the server https://github.com/webpack/webpack/blob/bac9b48bfb0f7dd9732f2faafb43ebb22ee2a2a7/hot/only-dev-server.js#L59-L67.

或者我推荐的是你可以使用我上面提到的webpack-dev-middleware和webpack-hot-middleware。这样,您不必担心代理逻辑​​,您可以轻松地将热重新加载到现有的快速服务器中,而无需使用webpack-dev-server。

Or what I recommend is that you can just use the webpack-dev-middleware and webpack-hot-middleware that I mentioned above instead. This way, you don't have to worrying about proxy logic and you can easily integrate hot reloading into your existing express server without the need for webpack-dev-server

这篇关于如果我正在使用像express这样的节点服务器,是否需要webpack-dev-server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆