我在 StackOverflow 和 GitHub 问题上也经历了很多答案,但是,我仍然被困在 Webpack 中的热模块替换中。我npm start
用来运行我的服务器webpack-dev-server --hot --inline
。我正在尝试更改我的 React 组件中的代码,但浏览器中没有任何反应。
我在 Ubuntu 14.04LTS 上使用 Google Chrome 版本 49.0.2623.87(64 位)。
在我的浏览器console
中,我收到的日志消息为
[HMR] 等待来自 WDS 的更新信号...
[WDS] 热模块更换已启用。
但是,没有发生热/实时重新加载。当我更改我的 React 组件文件中的代码时,什么都不会显示。我正在关注本教程的第一个视频Egghead.io/ReactFundamentals,一切正常。
以下是我的 package.json 和 webpack.config.js 文件。
包.json
{
"name": "react-fundamentals",
"version": "1.0.0",
"description": "Fundamentals of ReactJS",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --hot --inline"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^15.0.0-rc.2",
"react-dom": "^15.0.0-rc.2"
},
"devDependencies": {
"babel": "^6.5.2",
"babel-core": "^6.7.2",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"react-hot-loader": "^1.3.0",
"webpack": "^1.12.14",
"webpack-dev-server": "^1.14.1"
}
}
webpack.config.js
module.exports = {
context: __dirname,
entry: "./main.js",
output: {
path: __dirname,
filename: "bundle.js"
},
devServer: {
port: 7777
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel",
query: {
presets: ["es2015", "react"]
}
}
]
}
}
如果有人能指导我解决这个问题,那就太好了,因为我无法进一步有效地学习本教程。
更新我已经在下面发布了答案。