我正在尝试让热重载与我的设置一起使用。目前,它是这样工作的——
服务器.js
// this is the main server, which connects to db, serves react components, etc
const app = express();
app.get('/:params?*', (req, res) => {
res.status(200).send(`
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
hi
<script src="http://localhost:3000/build/client.js"></script>
</body>
</html>
`);
});
...
app.listen(5000);
gulpfile.babel.js
const CLIENT_DEV_CONFIG = {
entry: [
CLIENT_ENTRY,
'webpack-hot-middleware/client',
'eventsource-polyfill',
],
plugins: [
new webpack.HotModuleReplacementPlugin(),
],
output: {
...CLIENT_OUTPUT,
publicPath: 'http://localhost:3000/build/',
},
module: {
loaders: [BABEL_LOADER]
},
}
gulp.task('client-watch', done => {
console.log(CLIENT_DEV_CONFIG.output.publicPath);
const opts = {
hot: true,
publicPath: CLIENT_DEV_CONFIG.output.publicPath,
headers: {'Access-Control-Allow-Origin': '*'},
};
const app = new express();
const compiler = webpack(CLIENT_DEV_CONFIG);
app.use(webpackDevMiddleware(compiler, opts));
app.use(webpackHotMiddleWare(compiler));
app.listen(3000, (err) => {
console.log(err || '[webpack-hot-devserver] running on 3000');
done();
});
});
现在,
- 如果我访问
localhost:5000
. 有用 - 如果我访问
localhost:3000/build/client.js
,它也有效
但是,如果我更新了一些我没有得到实时更新的东西,我需要刷新...... :(
查看网络选项卡,我看到一个失败的请求 http://localhost:5000/__webpack_hmr
,我认为这可能是原因。
http://localhost:5000/__webpack_hmr
实际上应该是http://localhost:3000/__webpack_hmr
但是,我不知道如何纠正这个