代理自己的socket.io服务器时如何使webpack热模块替换(react-hot-loader)工作

时间:2016-01-28 08:15:20

标签: socket.io webpack webpack-hmr

我有一个使用socket.io的节点表达应用程序。 这个应用程序是通过webpack的开发服务器代理的,因为我想在客户端反应应用程序中使用热模块替换(它与节点应用程序上的套接字代码进行通信。)

如果我添加我的socket.io侦听器,它会破坏热模块替换的东西。我想因为我的听众正在接收消息而不是hmr监听器?

问题在于,当我保存一个热门加载的文件时,我会在chrome dev工具中获得以下内容并且没有热负载:

[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'
  }
};

0 个答案:

没有答案