A minimal React on Rails implementation of HMR with React Hot Loader 3, Redux, React Router 4, CSS modules and Webpack 2
bundle install
cd client && yarn
foreman start
- visit localhost:3000 and change source code to check out HMR
- in
package.json
- add
"react-hot-loader"
- add
- in
.babelrc
- use
es2015
preset, disablemodules
and add"react-hot-loader/babel"
plugin
- use
- in
webpack.config.js
- add
"react-hot-loader/patch"
right before your root source file (e.g.client/entry
in this rep) in to "entry" config - add
new webpack.HotModuleReplacementPlugin()
toplugins
config - add
hot: true
(orhotOnly: true)
, andheaders: { "Access-Control-Allow-Origin": "http://yourRailsHost" }
(or justheaders: { "Access-Control-Allow-Origin": "*" }
) todevServer
config
- add
- in your root source file (e.g.
client/entry.js
in this rep)- wrap your elements in
AppContainer
fromreact-hot-loader
package - use
module.hot.accept
and specify modules and how they are going to be replaced
- wrap your elements in
Check out the source code for more details.