2016-12-27 1347 views
10

我正在使用webpack-dev-server進行熱模塊更換。它工作的很好,但是這個錯誤每隔幾秒就會在控制檯中顯示出來:GET http://mysite:8080/__webpack_hmr 404 (Not Found)Webpack hmr:__webpack_hmr 404找不到

這裏是我的webpack.config.js:

var webpack = require('webpack'), 
    hostname = 'mysite', 
    port = 8080; 

module.exports = { 
    entry: [ 
     'babel-polyfill', 
     './src/js/main.js', 
     './dev/requireCss.js', 
     'webpack/hot/dev-server', 
     // I'm assuming the fault lies in the following line, but I can't figure out what's wrong 
     'webpack-hot-middleware/client?path=http://'+hostname+':'+port+'/__webpack_hmr' 
    ], 
    output: { 
     path: __dirname + '/webpack', 
     filename: "bundle.js", 
     publicPath: 'http://'+hostname+':'+port+'/' 
    }, 
    module: { 
     loaders: [{ 
      test: /\.jsx?$/, 
      exclude: /(node_modules|bower_components)/, 
      loaders: ['react-hot', 'babel-loader?presets[]=react&presets[]=es2015'] 
     } // removed some loaders for brevity 
     ] 
    }, 
    resolve: { 
     extensions: ['', '.json', '.js', '.jsx'] 
    }, 
    plugins: [ 
     new webpack.HotModuleReplacementPlugin() 
    ], 
    devtool: "source-map", 
    devServer: { 
     contentBase: __dirname + '/dev', 
     hot: true, 
     proxy: [{ 
      path: /\/(?!__webpack_hmr).+/, // I get the same error if I change this to 'path: /\/.+/' 
      target: 'http://my-backend.localhost' 
     }] 
    } 


}; 

的想法是,開發服務器應該轉發,除了從/__webpack_hmr到我的後端(my-backend.localhost)的所有請求。這適用於除__webpack_hmr之外的所有應用。

有什麼我可以在我的conf中改變,使錯誤消失?

回答

7

通過在下刪除以下行來修復條目'webpack-hot-middleware/client?path=http://'+hostname+':'+port+'/__webpack_hmr'。我不知道它爲什麼起作用。

+2

我真的不知道爲什麼我在配置文件中有類似的行,但它也適用於我。在安裝過程中查看其他項目時,肯定是我見過的。刪除該行,失去了錯誤,沒有性能問題。好,Hansn。 – DGaffneyDC

+2

沒有人...... –

+0

我認爲這與熱重裝有關,只能在開發環境中使用。 –