Created
April 21, 2016 22:58
-
-
Save thesabbir/fbd5904232d67e602905f9a1520b3057 to your computer and use it in GitHub Desktop.
Hot Reload Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"presets": ["es2015", "react"], | |
"plugins": ["react-hot-loader/babel"] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
const Hello = ({ name }) => <h1 > Hello {name} </h1> // Stateless/Pure component | |
export default class App extends Component { | |
render() { | |
return ( | |
<div> | |
<Hello name={'world'} /> | |
</div> | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AppContainer } from 'react-hot-loader'; // required | |
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import App from './App'; // App | |
const mountApp = document.getElementById('root'); | |
ReactDOM.render( | |
<AppContainer component={App} />, | |
mountApp | |
); | |
if (module.hot) { | |
module.hot.accept('./App', () => { | |
ReactDOM.render( | |
<AppContainer component={require('./App').default} />, | |
mountApp | |
); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const webpack = require('webpack'); | |
const WebpackDevServer = require('webpack-dev-server'); | |
const opener = require('opener'); | |
const config = require('./webpack.config.dev'); | |
const host = 'localhost'; | |
const port = 3000; | |
new WebpackDevServer(webpack(config), { | |
publicPath: config.output.publicPath, | |
hot: true, | |
historyApiFallback: true, | |
stats: { | |
colors: true // color is life | |
} | |
}) | |
.listen(port, host, (err) => { | |
if (err) { | |
console.log(err); | |
} | |
console.log(`Listening at ${host}:${port}`); | |
opener(`http://${host}:${port}`); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const webpack = require('webpack'); | |
module.exports = { | |
devtool: 'eval', | |
entry: [ | |
'react-hot-loader/patch', | |
'webpack-dev-server/client?http://localhost:3000', | |
'webpack/hot/only-dev-server', | |
'./app/main' | |
], | |
output: { | |
path: path.join(__dirname, 'build'), | |
filename: 'bundle.js', | |
publicPath: '/assets/' | |
}, | |
plugins: [ | |
new webpack.HotModuleReplacementPlugin() | |
], | |
module: { | |
loaders: [{ | |
test: /\.js$/, | |
loaders: ['babel'], | |
include: path.join(__dirname, 'src') | |
}] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment