我有一个使用 socket.io 的 node express 应用程序。这个应用程序通过 webpack 的开发服务器代理,因为我想在客户端反应应用程序中使用热模块替换(它与节点应用程序上的套接字代码通信。)
但是,如果我添加我的socket.io
听众,它会破坏热模块更换的东西。我猜是因为我的听众正在接收消息而不是 hmr 听众?
问题是,当我保存将热加载的文件时,我在 chrome 开发工具中得到以下内容并且没有热加载:
[WDS] App updated. Recompiling...
client?eeaa:52 [WDS] Proxy error.
client?eeaa:54 cannot proxy to http://127.0.0.1:1338 (read ECONNRESET)
client?eeaa:90 [WDS] App hot update...
socket.io.js:1456 GET http://localhost:1339/socket.io/?EIO=3&transport=polling&t=LA7JXr9&sid=r1NFzh1HOD5GcbN0AAAA 502 (Bad Gateway)
client?eeaa:25 [WDS] App updated. Recompiling...
client?eeaa:90 [WDS] App hot update...
socket.io.js:1456 POST http://localhost:1339/socket.io/?EIO=3&transport=polling&t=LA7Jckl&sid=r1NFzh1HOD5GcbN0AAAA 400 (Bad Request)
(主体400 (Bad Request)
是:
{"code":1,"message":"Session ID unknown"}
有人知道如何正确设置吗?
我webpack.config.js
目前是:
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: [
'webpack-dev-server/client?http://127.0.0.1:1339/',
'webpack/hot/only-dev-server',
'./src/client/main.js'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'client-bundle.js'
},
resolve: {
modulesDirectories: ['node_modules'],
extensions: ['', '.js']
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['react-hot', 'babel']
}, {
test: /\.css$/,
loader: 'style!css'
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
devtool: 'inline-source-map',
devServer: {
hot: true,
proxy: {
'*': 'http://127.0.0.1:' + (process.env.PORT || 1338)
},
host: '127.0.0.1'
}
};