[英]Webpack backend and frontend hot reloading
I am trying to use Webpack to live reload both my client side and server side code.我正在尝试使用 Webpack 实时重新加载我的客户端和服务器端代码。 The config I have at the moment will rebuild the files automatically when i run the webpack-dev-server
command.当我运行webpack-dev-server
命令时,我目前的配置将自动重建文件。 But nothing updates in the browser, even when I manually refresh it, same content on the screen但是浏览器中没有任何更新,即使我手动刷新它,屏幕上的内容也相同
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var nodeModules = {};
fs.readdirSync('node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod;
});
module.exports = {
entry: [ './server/server.js', './client/app.js'],
target: 'node',
output: {
path: path.join(__dirname, 'build'),
filename: '[name].js'
},
module: {
loaders: [{
exclude: /node_modules/,
loader: 'babel'
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
externals: nodeModules,
devServer: {
historyApiFallback: true,
contentBase: './'
}
};
There is a runtime API embedded in your environment for HMR that you have to interact with.您必须与之交互的 HMR 环境中嵌入了一个运行时 API。 At a minimum, you need to add the following somewhere in your entrypoint script:至少,您需要在入口点脚本中的某处添加以下内容:
if (module.hot) {
module.hot.accept()
}
Have a look at the code sample provided in the new documentation to get a better idea.查看新文档中提供的代码示例以获得更好的想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.