Feat: Add react-hot-loader

Combine webpack and browser-sync on one port
This commit is contained in:
Berkeley Martinez
2016-09-27 10:57:56 -07:00
parent d3f8757e92
commit a6f9e95ed8
7 changed files with 58 additions and 83 deletions

View File

@@ -28,8 +28,8 @@ import {
const isDev = Rx.config.longStackSupport = debug.enabled('fcc:*');
const log = debug('fcc:client');
const hotReloadTimeout = 5000;
const csrfToken = window.__fcc__.csrf.token;
const hotReloadTimeout = 2000;
const { csrf: { csrfToken } = {} } = window.__fcc__;
const DOMContainer = document.getElementById('fcc');
const initialState = isColdStored() ?
getColdStorage() :
@@ -37,7 +37,8 @@ const initialState = isColdStored() ?
initialState.app.csrfToken = csrfToken;
initialState.toasts = flashToToast(window.__fcc__.flash);
delete window.__fcc__;
// make empty object so hot reload works
window.__fcc__ = {};
const serviceOptions = { xhrPath: '/services', context: { _csrf: csrfToken } };
@@ -69,7 +70,10 @@ createApp({
})
.doOnNext(({ store }) => {
if (module.hot && typeof module.hot.accept === 'function') {
module.hot.accept('../common/app', function() {
module.hot.accept(err => {
if (err) { console.error(err); }
log('saving state and refreshing.');
log('ignore react ssr warning.');
saveToColdStorage(store.getState());
setTimeout(() => window.location.reload(), hotReloadTimeout);
});