【发布时间】:2015-09-30 03:33:33
【问题描述】:
我尝试使用热模块更换,但从未成功。 然后我找到了这个repository,它可以很好地使用热模块更换。而且它使用了一个 react-hot 加载器,如果我删除这个加载器,我会得到错误:
[HMR] Cannot find update. Need to do a full reload!
我根据上面的仓库调整了我的项目,但是我没有使用react,所以我没有使用react-hot loader,所以我总是得到上面的错误。
我可以在 webpack 中使用热模块替换但不使用 react 吗?或者我只需要一个 xx-hot loader 来使其热模块可更换?
我的结构:
src
entry.js
index.html
server.js
webpack.config.js
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script src="/static/bundle.js"></script>
</body>
</html>
entry.js:
document.write('hello');
server.js:
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true
}).listen(3000, 'localhost', function (err, result) {
if (err) {
console.log(err);
}
console.log('Listening at localhost:3000');
});
webpack.config.js:
var path = require("path");
var webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
"./src/entry.js"
],
output: {
path: path.join(__dirname, "build"),
publicPath: '/static/',
filename: "bundle.js"
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
};
【问题讨论】:
-
尝试用
publicPath: 'http://localhost:3000/static/'改变你的输出
标签: webpack