Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Get react hot module loading working
Browse files Browse the repository at this point in the history
It's never gunna be amazing because we lazy render all the endpoints...
  • Loading branch information
Dom Harrington committed Feb 8, 2018
1 parent 3cc2d9b commit 2e318aa
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 4 deletions.
12 changes: 10 additions & 2 deletions example/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ require('babel-polyfill');

const React = require('react');
const ReactDOM = require('react-dom');
const { AppContainer } = require('react-hot-loader');

const Demo = require('./src/Demo');
function render(Component) {
ReactDOM.render(<AppContainer><Component /></AppContainer>, document.getElementById('hub-content'));
}

ReactDOM.render(<Demo />, document.getElementById('hub-content'));
render(require('./src/Demo'));

// Webpack Hot Module Replacement API
if (module.hot) {
module.hot.accept('./src/Demo', () => render(require('./src/Demo')));
}
100 changes: 100 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"scripts": {
"test": "eslint -f unix example && lerna run test --parallel",
"start": "node scripts/update-example-swagger-files && webpack && webpack-dev-server",
"start": "node scripts/update-example-swagger-files && webpack-dev-server",
"build": "./build.sh & lerna run build",
"watch": "lerna run watch --stream",
"deploy": "gh-pages --dotfiles -d example/dist",
Expand Down Expand Up @@ -45,6 +45,7 @@
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-hot-loader": "^3.1.3",
"swagger2openapi": "^2.9.2"
}
}
2 changes: 1 addition & 1 deletion webpack.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
entry: './example/index.jsx',
entry: ['react-hot-loader/patch', './example/index.jsx'],
module: {
rules: [
{
Expand Down
6 changes: 6 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.common');

Expand All @@ -9,5 +10,10 @@ module.exports = merge(common, {
contentBase: './example',
compress: true,
port: 9966,
hot: true,
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
],
});

0 comments on commit 2e318aa

Please sign in to comment.