首页 文章

使用browserify,redux和react-route重新加载热模块

提问于
浏览
0

我更喜欢浏览webify而不是webpack,但有's a problem in browserify environment I can't修复 . 我'm using react, redux and react-route and I' m愿意像hot-hot-loader为webpack环境提供热模块重新加载 . 我'm using livereactload to achieve this (tried browserify-hmr too) the problem is it doesn'使用redux . 它的redux示例(https://github.com/milankinen/livereactload/blob/master/examples/02-redux)不适用于新的克隆 . 有可能吗?有人可以给我更改以应用于示例以使其工作吗?

附:看看这个问题https://github.com/milankinen/livereactload/issues/64

2 回答

  • 0

    我正在使用它,但作为一个watchify插件:插件(require('livereactload')),它工作得很好 .

    我确实改变了LiveReactload :: Bundle并更新了页面但是这个警告:browser.js:51警告:[react-router]你无法改变;它会被忽略 .

    它仍然“本地”重新加载,但它不是一个“真正的”热重新加载,因为许多东西仍然重新渲染,并没有达到我想要的程度 .

    我们需要添加到配置存储的唯一内容如下:

    export default function configureStore(initialState) {
      const store = createStoreWithMiddleware(rootReducer, initialState);
    
      // React hot reload
      if (module.onReload) {
        module.onReload(() => {
          const nextReducer = require('../reducers');
          store.replaceReducer(nextReducer.default || nextReducer);
          // return true to indicate that this module is accepted and
          // there is no need to reload its parent modules
          return true;
        });
      }
    
      return store;
    }
    
  • 2

    我在 redux 的问题是我没有使用 react-proxy@1.x 也没有使用 babel-plugin-react-transform 所以我的组件没有包含在代理中 . 新版本的livereactload会在没有 react-proxybabel-plugin-react-transform 的情况下使用它时引发错误:https://github.com/milankinen/livereactload/issues/64#issuecomment-231992217

    我在 react-route 的问题是我在Route指令中使用了一个定义为箭头函数的组件 . 显然 livereactload 不支持这一点 . 它通过使用类组件而不是箭头函数来解决 . 这里的解释:https://github.com/milankinen/livereactload/issues/43#issuecomment-231990841

相关问题