We started with custom webpack config (without any boilerplate)
- Webpack 2.0
- Webpack-server
- Lots of code have been already written
- Babel
- Sass + PostCss
Firstly, we tried to implement styles hot-reloading, but because we use import styles from './index.scss' we must reload the whole file, so why not implement react commponents update with react-hot-load.
You can find most of the information in this posts (read in order):
- gaearon/react-hot-loader#243 (comment)
- gaearon/react-hot-loader#243 (comment)
- https://gaearon.github.io/react-hot-loader/getstarted/
- AppContainer IS REACT-HOT-MODULE COMPONENT. I didnt pay my attention to this component, because i was thinking it must be one of projects component.
- You MUST reqire new instance of your main component (that is in ReactDOM.render) when module.hot.accept callback triggers.
- You can import "react-hot-loader/patch" in you entry file on the top of it
So you must create function (lets call it main) that will import \ require your main component (like Provider or Router or anything else), that must be in AppContainer component and return all of this. Then you use main in your entry file and in module.hot.accept callback
MyApp.js
import { AppContainer } from 'react-hot-loader'
const MyApp = () => {
return(
<AppContainer>
// Your component like <Provider> or <Router> or anything else
</AppContainer>
)
}
index.js
function main(){
const MyApp = require('pathTo/MyApp').default
ReactDom.render(MyApp, document.getElementById(...),
}
main()
if (module.hot) {
module.hot.accept('pathTo/MyApp', () => {
main()
})
}