forked from react-boilerplate/react-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
82 lines (72 loc) · 2.92 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
*
* app.js
*
* This is the entry file for the application, mostly just setup and boilerplate
* code. Routes are configured at the end of this file!
*
*/
// Load the ServiceWorker, the Cache polyfill, the manifest.json file and the .htaccess file
import 'file?name=[name].[ext]!../serviceworker.js';
import 'file?name=[name].[ext]!../manifest.json';
import 'file?name=[name].[ext]!../.htaccess';
// Check for ServiceWorker support before trying to install it
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/serviceworker.js').then(() => {
// Registration was successful
}).catch(() => {
// Registration failed
});
} else {
// No ServiceWorker Support
}
// Import all the third party stuff
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { Router, Route } from 'react-router';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import FontFaceObserver from 'fontfaceobserver';
import createHistory from 'history/lib/createBrowserHistory';
// Observer loading of Open Sans (to remove open sans, remove the <link> tag in the index.html file and this observer)
const openSansObserver = new FontFaceObserver('Open Sans', {});
// When Open Sans is loaded, add the js-open-sans-loaded class to the body
openSansObserver.check().then(() => {
document.body.classList.add('js-open-sans-loaded');
}, () => {
document.body.classList.remove('js-open-sans-loaded');
});
// Import the pages
import HomePage from './components/pages/HomePage.react';
import ReadmePage from './components/pages/ReadmePage.react';
import NotFoundPage from './components/pages/NotFound.react';
import App from './components/App.react';
// Import the CSS file, which HtmlWebpackPlugin transfers to the build folder
import '../css/main.css';
// Create the store with the redux-thunk middleware, which allows us
// to do asynchronous things in the actions
import rootReducer from './reducers/rootReducer';
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
const store = createStoreWithMiddleware(rootReducer);
// Make reducers hot reloadable, see http://stackoverflow.com/questions/34243684/make-redux-reducers-and-other-non-components-hot-loadable
if (module.hot) {
module.hot.accept('./reducers/rootReducer', () => {
const nextRootReducer = require('./reducers/rootReducer').default;
store.replaceReducer(nextRootReducer);
});
}
// Mostly boilerplate, except for the Routes. These are the pages you can go to,
// which are all wrapped in the App component, which contains the navigation etc
ReactDOM.render(
<Provider store={store}>
<Router history={createHistory()}>
<Route component={App}>
<Route path="/" component={HomePage} />
<Route path="/readme" component={ReadmePage} />
<Route path="*" component={NotFoundPage} />
</Route>
</Router>
</Provider>,
document.getElementById('app')
);