当它加载时一切正常,而且HMR也工作正常。然后出现了这个错误。
GET http://localhost:3000/__webpack_hmr net::ERR_INCOMPLETE_CHUNKED_ENCODING
就好像webpackdevserver崩溃然后重新启动一样,需要几秒钟时间,然后hmr又可以正常工作了。
[HMR] connected
然后就会“崩溃”等等......
看起来我只在Chrome(版本55)中遇到了这个问题(在Mozilla中测试,没有出现这个问题)。
可能是我在webpack或node配置中漏掉了一些东西,但是在文档中找不到相关内容。
有什么想法可以解决这个问题吗?
//以下是webpack配置
const path = require('path');
const merge = require('webpack-merge');
const TARGET = process.env.NODE_ENV;
process.env.BABEL_ENV = TARGET;
const webpack = require('webpack');
const NpmInstallPlugin = require('npm-install-webpack-plugin');
const PATHS = {
app: path.join(__dirname, 'client'),
build: path.join(__dirname, 'build')
};
const common = {
entry: {
app: [PATHS.app, 'webpack-hot-middleware/client']
},
resolve: {
extensions: ['', '.js', '.jsx']
},
output: {
path: PATHS.build,
filename: 'bundle.js',
publicPath: '/'
},
module: {
loaders: [
{
test: /\.css$/,
loaders: ['style', 'css'],
include: PATHS.app
},
{
test: /\.jsx?$/,
loaders:['babel?cacheDirectory=true'],
include: PATHS.app
}
]
}
};
if(TARGET === 'dev' || ! TARGET) {
module.exports = merge(common, {
// devServer: {
// contentBase: PATHS.build,
// historyApiFallback: true,
// hot: true,
// inline: true,
// progress: true,
// stats: 'error-only',
// host: 'http://127.0.0.1/',
// port: 3000
// },
export: {
isDev: true
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('dev')
}),
new NpmInstallPlugin({
save: true
})
],
devtool: 'eval-source-map'
});
}
if(TARGET === "build") {
module.exports = merge(common, {});
}
// Node.js 路由
this.app.get('/', function(req,res) {
res.sendFile(path.join(__dirname, './../../build/index.html'))
})
// index.html
<!DOCTYPE html>
<html>
<head>
<title> Ripple Data Analyzer</title>
</head>
<body>
<div id='root'>
</div>
<script src="bundle.js"></script>
</body>
</html>
//index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App.jsx';
ReactDOM.render(<App/>, document.getElementById('root'));