Reactjs 使用react redux创建react应用程序的HMR
使用Reactjs 使用react redux创建react应用程序的HMR,reactjs,webpack,redux,react-router-redux,webpack-hmr,Reactjs,Webpack,Redux,React Router Redux,Webpack Hmr,使用create-react-app初始化的应用程序未启用HMR。这里有一篇关于如何启用它的博客文章: routes.js import React from 'react' import { Provider } from 'react-redux' import store from './store/store' import routes from './routes' const App = ( <Provider store={store}> { route
create-react-app
初始化的应用程序未启用HMR。这里有一篇关于如何启用它的博客文章:
routes.js
import React from 'react'
import { Provider } from 'react-redux'
import store from './store/store'
import routes from './routes'
const App = (
<Provider store={store}>
{ routes }
</Provider>
);
export default App;
import React from 'react';
import { browserHistory, Router, Route } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import store from '../store/store';
import { AnonymousLayout } from '../layouts';
import { LoginForm } from './Login';
const history = syncHistoryWithStore(browserHistory, store);
export default (
<Router history={history}>
<Route path="/" component={AnonymousLayout}>
<Route path="/login" component={LoginForm} />
</Route>
</Router>
);
import React from 'react'
import ReactDOM from 'react-dom'
import App from './client/App';
const rootEl = document.getElementById('root');
ReactDOM.render(
App,
rootEl
);
if (module.hot) {
module.hot.accept('./client/App', () => {
const NextApp = './client/App';
ReactDOM.render(
<NextApp />,
rootEl
);
});
}
// regular imports
ReactDOM.render(<App /> , document.getElementById('root'))
if (module.hot) {
module.hot.accept('./App', () => {
ReactDOM.render(<App />, document.getElementById('root'))
})
}
import { createStore } from 'redux'
import rootReducer from './reducers'
const configureStore = () => {
const store = createStore(rootReducer)
if (process.env.NODE_ENV !== "production") {
if (module.hot) {
module.hot.accept('./reducers', () => {
store.replaceReducer(rootReducer)
})
}
}
return store
}
export default configureStore
从“React”导入React;
从“react Router”导入{browserHistory,Router,Route};
从“react router redux”导入{syncHistoryWithStore};
从“../store/store”导入存储;
从“../layouts”导入{AnonymousLayout};
从“./Login”导入{LoginForm};
const history=syncHistoryWithStore(浏览器历史记录,存储);
导出默认值(
);
index.js
import React from 'react'
import { Provider } from 'react-redux'
import store from './store/store'
import routes from './routes'
const App = (
<Provider store={store}>
{ routes }
</Provider>
);
export default App;
import React from 'react';
import { browserHistory, Router, Route } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import store from '../store/store';
import { AnonymousLayout } from '../layouts';
import { LoginForm } from './Login';
const history = syncHistoryWithStore(browserHistory, store);
export default (
<Router history={history}>
<Route path="/" component={AnonymousLayout}>
<Route path="/login" component={LoginForm} />
</Route>
</Router>
);
import React from 'react'
import ReactDOM from 'react-dom'
import App from './client/App';
const rootEl = document.getElementById('root');
ReactDOM.render(
App,
rootEl
);
if (module.hot) {
module.hot.accept('./client/App', () => {
const NextApp = './client/App';
ReactDOM.render(
<NextApp />,
rootEl
);
});
}
// regular imports
ReactDOM.render(<App /> , document.getElementById('root'))
if (module.hot) {
module.hot.accept('./App', () => {
ReactDOM.render(<App />, document.getElementById('root'))
})
}
import { createStore } from 'redux'
import rootReducer from './reducers'
const configureStore = () => {
const store = createStore(rootReducer)
if (process.env.NODE_ENV !== "production") {
if (module.hot) {
module.hot.accept('./reducers', () => {
store.replaceReducer(rootReducer)
})
}
}
return store
}
export default configureStore
从“React”导入React
从“react dom”导入react dom
从“./client/App”导入应用程序;
const rootEl=document.getElementById('root');
ReactDOM.render(
应用程序,
罗特尔
);
如果(模块热){
module.hot.accept('./客户端/应用程序',()=>{
const nextap='/客户端/应用程序';
ReactDOM.render(
,
罗特尔
);
});
}
然而,我只是得到了这个错误:
警告:[反应路由器]您无法更改;它将被忽略
有没有办法将HMR破解到这个项目中?您需要导入AppContainer并用它包装您的NextApp容器
import { AppContainer } from 'react-hot-loader';
...
...
if (module.hot) {
module.hot.accept('./client/App', () => {
const NextApp = './client/App';
ReactDOM.render(
<AppContainer />
<NextApp />
<AppContainer />,
rootEl
);
});
}
从'react hot loader'导入{AppContainer};
...
...
如果(模块热){
module.hot.accept('./客户端/应用程序',()=>{
const nextap='/客户端/应用程序';
ReactDOM.render(
丹·阿布拉莫夫适合我的情况:
index.js
import React from 'react'
import { Provider } from 'react-redux'
import store from './store/store'
import routes from './routes'
const App = (
<Provider store={store}>
{ routes }
</Provider>
);
export default App;
import React from 'react';
import { browserHistory, Router, Route } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import store from '../store/store';
import { AnonymousLayout } from '../layouts';
import { LoginForm } from './Login';
const history = syncHistoryWithStore(browserHistory, store);
export default (
<Router history={history}>
<Route path="/" component={AnonymousLayout}>
<Route path="/login" component={LoginForm} />
</Route>
</Router>
);
import React from 'react'
import ReactDOM from 'react-dom'
import App from './client/App';
const rootEl = document.getElementById('root');
ReactDOM.render(
App,
rootEl
);
if (module.hot) {
module.hot.accept('./client/App', () => {
const NextApp = './client/App';
ReactDOM.render(
<NextApp />,
rootEl
);
});
}
// regular imports
ReactDOM.render(<App /> , document.getElementById('root'))
if (module.hot) {
module.hot.accept('./App', () => {
ReactDOM.render(<App />, document.getElementById('root'))
})
}
import { createStore } from 'redux'
import rootReducer from './reducers'
const configureStore = () => {
const store = createStore(rootReducer)
if (process.env.NODE_ENV !== "production") {
if (module.hot) {
module.hot.accept('./reducers', () => {
store.replaceReducer(rootReducer)
})
}
}
return store
}
export default configureStore
我能够使用Dan Abramov在“从创建react应用程序迁移”中的描述,我在一个Raspberry Pi(raspbian)上用流行的7英寸LCD触摸屏设置了这个
为了增加额外的扭曲,我使用了“NetTalk”文件系统共享,让Raspbian文件系统在OSX上显示为卷,这样我就可以在Macbook上的Atom编辑器中编辑应用程序源代码,而应用程序在Raspberry上运行。
当我在Atom中编辑源代码并保存文件时,应用程序会在Raspberry上重新编译,热模块替换会在Raspberry LCD上显示更改,而不会产生刷新效果。Raspberry的性能不是最好的,所以需要几秒钟的时间来进行更改,但非常酷
真正的向导可以尝试进一步将源代码在Macbook上编译(Macbook具有更高的CPU能力)并在何处编译代码
仍然在Raspberry上运行和HMR更新。但从HMR的角度来看,该方案看起来如何?我不确定如何完成分区。我创建了一个示例repo,它支持HMR和Redux。
使用Hmm使用HMR进行反应和重新复制,尝试了这个和一些排列,但始终无法使其工作。您能分享一个包含所有代码的小型回购协议吗(例如store.js/index.js/app.js)?我似乎无法使其工作:(当我导出默认配置存储时,我会遇到各种各样的错误。尽管当我导出默认配置存储时()
没有错误(但对于redux Reducer仍然没有HMR),现在更容易了。请。