Skip to content

Commit

Permalink
Fix the old HMR issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Sep 9, 2017
1 parent 7b25df8 commit b9d6af4
Show file tree
Hide file tree
Showing 10 changed files with 454 additions and 145 deletions.
31 changes: 0 additions & 31 deletions build/dev-server.js

This file was deleted.

2 changes: 1 addition & 1 deletion build/webpack.config.dev.js
Expand Up @@ -19,8 +19,8 @@ module.exports = {
entry: [
'babel-polyfill',
'react-hot-loader/patch',
'webpack-hot-middleware/client?reload=true',
'whatwg-fetch',
'classlist-polyfill',
'./src/index'
],
cache: true,
Expand Down
1 change: 1 addition & 0 deletions build/webpack.config.prod.js
Expand Up @@ -10,6 +10,7 @@ module.exports = {
entry: [
'babel-polyfill',
'whatwg-fetch',
'classlist-polyfill',
path.join(__dirname, '../src/index')
],
cache: false,
Expand Down
1 change: 1 addition & 0 deletions build/webpack.config.test.js
Expand Up @@ -5,6 +5,7 @@ module.exports = {
entry: [
'babel-polyfill',
'whatwg-fetch',
'classlist-polyfill',
path.join(__dirname, '../src/index')
],
devtool: 'eval',
Expand Down
11 changes: 3 additions & 8 deletions package.json
@@ -1,8 +1,7 @@
{
"name": "pixiv.moe",
"version": "1.2.3",
"version": "1.2.4",
"description": "Source code of https://pixiv.moe",
"main": "server.js",
"scripts": {
"clean": "rimraf dist/*",
"copy": "copyfiles -f ./src/index.html ./src/CNAME ./dist",
Expand All @@ -12,7 +11,7 @@
"lint": "eslint --max-warnings 0 ./src",
"lint:fix": "eslint --fix ./src",
"posttest": "npm run lint",
"start": "cross-env NODE_ENV=development node build/dev-server.js",
"start": "cross-env NODE_ENV=development webpack-dev-server --progress --config build/webpack.config.js",
"test": "cross-env NODE_ENV=test karma start && npm run test:api",
"test:watch": "cross-env NODE_ENV=test karma start --autoWatch=true --singleRun=false",
"test:api": "cross-env NODE_ENV=test:mocha mocha --compilers js:babel-register --require babel-polyfill --timeout 30000 test/**/*.mocha.js",
Expand Down Expand Up @@ -60,7 +59,6 @@
"eslint-loader": "^1.9.0",
"eslint-plugin-react": "^7.2.1",
"expect": "^1.20.2",
"express": "^4.15.4",
"fetch-mock": "^5.12.2",
"file-loader": "^0.11.2",
"gh-pages": "^1.0.0",
Expand All @@ -76,7 +74,6 @@
"karma-mocha-reporter": "^2.0.0",
"karma-sourcemap-loader": "^0.3.5",
"karma-webpack": "^2.0.4",
"log-update": "^2.1.0",
"minimist": "^1.2.0",
"mocha": "^3.5.0",
"nock": "^9.0.14",
Expand All @@ -96,8 +93,7 @@
"url-loader": "^0.5.9",
"webpack": "^3.5.5",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-middleware": "^1.12.0",
"webpack-hot-middleware": "^2.18.2",
"webpack-dev-server": "^2.7.1",
"webpack-merge": "^4.1.0"
},
"dependencies": {
Expand All @@ -122,7 +118,6 @@
"react-modal": "^2.2.4",
"react-redux": "^5.0.6",
"react-router-dom": "^4.1.2",
"react-router-redux": "next",
"react-tap-event-plugin": "^2.0.1",
"redux": "^3.7.2",
"redux-thunk": "^2.1.0",
Expand Down
43 changes: 17 additions & 26 deletions src/containers/AppContainer.js
@@ -1,16 +1,12 @@
import React from 'react';
import { Route, Switch } from 'react-router-dom';
import { ConnectedRouter } from 'react-router-redux';
import { Provider } from 'react-redux';
import injectTapEventPlugin from 'react-tap-event-plugin';
import { Router, Route, Switch } from 'react-router-dom';
import 'react-mdl/extra/material.js';
import 'material-design-icons/iconfont/material-icons.css';
import '@/styles/mdl/material-design-lite.scss';
import '@/styles/Base.scss';
import '@/styles/Reset.scss';
import 'classlist-polyfill';

import { configureStore, history } from '@/stores';
import { history } from '@/stores';
import {
GalleryContainer,
IllustContainer,
Expand All @@ -19,33 +15,28 @@ import {
} from '@/containers';
import { ScrollContext, TrackPageView } from '@/components';

injectTapEventPlugin();
const store = configureStore();

export default class AppContainer extends React.Component {
constructor(props) {
super(props);
}

render() {
return (
<Provider store={store}>
<ConnectedRouter history={history}>
<ScrollContext>
<TrackPageView>
<Switch>
<Route exact path="/" component={GalleryContainer} />
<Route
path="/illust/:illustId(\d+)"
component={IllustContainer}
/>
<Route path="/:illustId(\d+)" component={RedirectContainer} />
<Route component={NotFoundContainer} />
</Switch>
</TrackPageView>
</ScrollContext>
</ConnectedRouter>
</Provider>
<Router history={history}>
<ScrollContext>
<TrackPageView>
<Switch>
<Route exact path="/" component={GalleryContainer} />
<Route
path="/illust/:illustId(\d+)"
component={IllustContainer}
/>
<Route path="/:illustId(\d+)" component={RedirectContainer} />
<Route component={NotFoundContainer} />
</Switch>
</TrackPageView>
</ScrollContext>
</Router>
);
}
}
20 changes: 15 additions & 5 deletions src/index.js
@@ -1,15 +1,24 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { AppContainer as Root } from 'react-hot-loader';
import { Provider } from 'react-redux';
import injectTapEventPlugin from 'react-tap-event-plugin';

import { AppContainer } from '@/containers';
import { configureStore } from '@/stores';
import AppContainer from '@/containers/AppContainer';

injectTapEventPlugin();

const store = configureStore();

// Render the main component into the dom
const render = Component => {
ReactDOM.render(
<Root>
<Component />
</Root>,
<Provider store={store}>
<Root>
<Component />
</Root>
</Provider>,
document.getElementById('app')
);
};
Expand All @@ -18,6 +27,7 @@ render(AppContainer);

if (module.hot) {
module.hot.accept('@/containers/AppContainer', () => {
render(AppContainer);
const NextAppContainer = require('@/containers/AppContainer').default;
render(NextAppContainer);
});
}
4 changes: 1 addition & 3 deletions src/reducers/index.js
@@ -1,13 +1,11 @@
import { combineReducers } from 'redux';
import { routerReducer } from 'react-router-redux';

import gallery from '@/reducers/gallery';
import illust from '@/reducers/illust';

const reducers = combineReducers({
gallery,
illust,
router: routerReducer
illust
});

export default reducers;
6 changes: 1 addition & 5 deletions src/stores/index.js
@@ -1,17 +1,13 @@
import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import createHistory from 'history/createBrowserHistory';
import { routerMiddleware } from 'react-router-redux';

import rootReducer from '@/reducers';

// Create a history of your choosing (we're using a browser history in this case)
export const history = createHistory();
// Build the middleware for intercepting and dispatching navigation actions
const createStoreWithMiddleware = applyMiddleware(
thunkMiddleware,
routerMiddleware(history)
)(createStore);
const createStoreWithMiddleware = applyMiddleware(thunkMiddleware)(createStore);

export function configureStore(initialState) {
let store;
Expand Down

0 comments on commit b9d6af4

Please sign in to comment.