add hot reload support
Change-Id: I29cf167e3ec96ffa046d454863f4dbf0eebcd9f4
diff --git a/app.js b/app.js
index 065724b..f429b22 100644
--- a/app.js
+++ b/app.js
@@ -22,11 +22,20 @@
const JamiRestApi = require('./routes/jami')
const JamiDaemon = require('./JamiDaemon')
+const webpack = require('webpack')
+const webpackConfig = require('./client/webpack.config.js')
+const compiler = webpack(webpackConfig)
+
//const sessionStore = new RedisStore({ client: redis })
const sessionStore = new session.MemoryStore()
const app = express()
-
+app.use(
+ require('webpack-dev-middleware')(compiler, {
+ publicPath: webpackConfig.output.publicPath
+ })
+ );
+ app.use(require('webpack-hot-middleware')(compiler));
/*
Configuation for Passeport Js
*/
diff --git a/client/src/index.js b/client/src/index.js
index b39e2f5..f4c1f23 100644
--- a/client/src/index.js
+++ b/client/src/index.js
@@ -3,15 +3,25 @@
import './index.scss';
import App from './App';
//import * as serviceWorker from './serviceWorker';
+const rootEl = document.getElementById('root');
+const render = Component =>
ReactDOM.render(
<React.StrictMode>
- <App />
+ <Component />
</React.StrictMode>,
- document.getElementById('root')
+ rootEl
);
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
//serviceWorker.unregister();
+render(App)
+if (module.hot) module.hot.accept('./App', () => {
+ try {
+ render(App)
+ } catch (e) {
+ location.reload()
+ }
+})
\ No newline at end of file
diff --git a/client/webpack.config.js b/client/webpack.config.js
index c02de06..6f02eac 100644
--- a/client/webpack.config.js
+++ b/client/webpack.config.js
@@ -1,13 +1,17 @@
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
+const webpack = require('webpack')
module.exports = {
- entry: path.resolve(__dirname, 'src', 'index.js'),
+ entry: ['react-hot-loader/patch',
+ 'webpack-hot-middleware/client',
+ path.resolve(__dirname, 'src', 'index.js')],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/'
},
+ devtool: 'inline-source-map',
mode: 'development',
module: {
rules: [
@@ -28,6 +32,7 @@
]
},
plugins: [
+ new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.ejs')
})
diff --git a/package.json b/package.json
index 32cb111..910c756 100644
--- a/package.json
+++ b/package.json
@@ -27,7 +27,10 @@
},
"devDependencies": {
"llnode": "^3.2.0",
- "nodemon": "^2.0.7"
+ "nodemon": "^2.0.7",
+ "react-hot-loader": "^4.13.0",
+ "webpack-dev-middleware": "^4.1.0",
+ "webpack-hot-middleware": "^2.25.0"
},
"scripts": {
"start": "node app.js",