当我在组件中进行更改时,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
当我进行复杂的更改时,我经常会收到以下错误消息(尽管如果我更改 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/