javascript - 热加载器复制代码(n 次)而不是热交换

标签 javascript node.js reactjs webpack-dev-server react-hot-loader

当我在组件中进行更改时,webpack 会重新编译并对模块进行热交换。但是现在我的代码运行了 n 次,其中 n 是次热模块交换已经发生。例如,我进行了更改,现在函数运行了两次。我做了另一个更改,函数运行了 3 次。我可以在商店的 dispatchToken 中放置一个 console.log(Date.now()),我可以看到它正在运行 n 次。

商店:http://pastebin.com/PVnyf572

webpack.config.js:http://pastebin.com/MsziqH9v

然后我使用 webpack-dev-server app/client.js --inline --hot --colors

运行 webpack-dev-server

当我进行复杂的更改时,我经常会收到以下错误消息(尽管如果我更改 Store 的第 60 行以增加 10,而不是 6,则不会发生这种情况):

It appears that React Hot Loader isn't configured correctly. If you're using NPM, make sure your dependencies don't drag duplicate React distributions into their node_modules and that require("react") corresponds to the React instance you render your app with. If you're using a precompiled version of React, see https://github.com/gaearon/react-hot-loader/tree/master/docs#usage-with-external-react for integration instructions.

最佳答案

我认为你的 webpack 配置不合适。使用此样板然后运行您的代码我认为您的问题将得到解决

https://github.com/tapos007/ReactJS-MobX-Webpack-Boilerplate

关于javascript - 热加载器复制代码(n 次)而不是热交换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38281062/

相关文章:

javascript - 像选取框一样生成动画

javascript - 视口(viewport)高度差中断滚动事件

node.js - nodejs代理超时后不断开连接

reactjs - Redux 状态的嵌套对象可用,但在组件内不可访问

javascript - React Hooks 模态传递状态?

html - 仅向上扩展并以最大高度滚动的 Div

javascript - jQuery ajax 插件获取输入的值

javascript - 无法对使用类选择器检索到的元素执行任何操作

node.js - 在node js & express中,settings和locals有什么区别

javascript - 返回node.js中的目录(fs.readFileSync)