0

因此,目前我正在開發一個.NET MVC應用程序,其中一部分應用程序是客戶端使用reactjs完全呈現的門戶。無法獲取在不同端口上工作的熱模塊替換

基本上我有我的門戶的index.cshtml文件看起來是這樣的:

<html lang="en"> 
<head> 
    <title>User Portal</title> 
</head> 

<body> 
    <div id="app"></div> 
    <script src="http://localhost:3000/bundle.js"></script> 
</body> 
</html> 

和我的客戶端應用程序reactjs端口上運行concurently:使用Express服務器3000。我通過localhost:53079訪問我的主MVC應用程序。我想知道是否有可能讓熱模塊重新加載53079端口,因爲這是我如何訪問我的應用程序?

我webpack.config.dev.js看起來是這樣的:

export default { 
    debug: true, 
    devtool: 'inline-source-map', 
    noInfo: false, 
    entry: [ 
    'eventsource-polyfill', // necessary for hot reloading with IE 
    'webpack-hot-middleware/client?reload=true', //note that it reloads the page if hot module reloading fails. 
    path.resolve(__dirname, 'src/index') 
    ], 
    target: 'web', 
    output: { 
    path: __dirname + '/dist', // Note: Physical files are only output by the production build task `npm run build`. 
    publicPath: 'http://localhost:3000/', 
    filename: 'bundle.js' 
    }, 
    devServer: { 
    contentBase: path.resolve(__dirname, 'src') 
    }, 
    plugins: [ 
    new webpack.HotModuleReplacementPlugin(), 
    new webpack.NoErrorsPlugin() 
    ], 
    module: { 
    //..... 
    } 
}; 

我試圖修改devServer的端口號,以及在沒有任何運氣的輸出路徑。我也能夠找到關於如何配置hmr端口號的很少的閱讀。目前我的控制檯正被下列錯誤信息所遺留:

EventSource的響應具有非「text/event-stream」的MIME類型(「text/html」)。中止連接。

+0

您是否曾經找到過解決方案?升級到.net核心2後,我遇到與Angular 2相同的問題。 我的結局是,路由正在提取對__webpack_hmr的請求,並且SPA後備路由啓動並將其路由到索引,因此hmr的請求實際上是返回一個網頁,因此'text/html'。如果我能弄清楚爲什麼或者如何解決它,那該死的! – yanbu

+0

是的,同樣的事情在這裏......不幸的是一直沒有找到解決方案,並且幾乎已經放棄了HMR的併發開發。 –

回答

0

我想通了,你需要設置選項指向你的hmr端點。

app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { 
      HotModuleReplacement = true, 
      HotModuleReplacementEndpoint = "/dist/__webpack_hmr" 
     });