Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
eezhal92 committed Jun 8, 2017
0 parents commit 180a90a
Show file tree
Hide file tree
Showing 15 changed files with 3,438 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": [
["es2015", { "modules": false }],
"react"
],
"plugins": [
"react-hot-loader/babel",
]
}
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# editorconfig.org
root = true

[*]

charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dist
/node_modules

*.log
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="root"></div>
<script src="/static/vendor.js"></script>
<script src="/static/app.js"></script>
</body>
</html>
15 changes: 15 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"restartable": "rs",
"ignore": [
".git",
"node_modules/**/node_modules"
],
"verbose": true,
"watch": [
"server.js"
],
"env": {
"NODE_ENV": "development"
},
"ext": "js json"
}
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"scripts": {
"dev": "nodemon server.js"
},
"dependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"body-parser": "^1.17.2",
"express": "^4.15.3",
"nodemon": "^1.11.0",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-hot-loader": "3.0.0-beta.7",
"react-router": "3.0.5",
"webpack": "^2.6.1",
"webpack-dev-middleware": "^1.10.2",
"webpack-hot-middleware": "^2.18.0"
}
}
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## react-router-hmr-case

How to make react router v3 works with react-hot-loader

`npm run dev`
37 changes: 37 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const express = require('express');
const { resolve } = require('path');
const bodyParser = require('body-parser');

const app = new express();
const PORT = process.env.PORT || 3000;
const ENV = process.env.NODE_ENV;

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const webpackConfig = require('./webpack.config');

const compiler = webpack(webpackConfig);

app.use(webpackDevMiddleware(compiler, {
hot: true,
publicPath: webpackConfig.output.publicPath,
inline: true,
noInfo: true,
}));
app.use(webpackHotMiddleware(compiler));

app.use(express.static(resolve(__dirname, '../dist')));
app.use('/', (req, res) => {
res
.sendFile(resolve(__dirname, 'index.html'));
});

// Run server
app.listen(PORT, () => {
// eslint-disable-next-line no-console
console.log(`running on http://localhost:${PORT} in ${ENV} enviroment `);
});
18 changes: 18 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { Link } from 'react-router';

class App extends React.Component {
render() {
const { children } = this.props;

return (
<div>
<Link to='/'>Home</Link> | <Link to='/about'>About</Link>
<br />
{children}
</div>
);
}
}

export default App;
29 changes: 29 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import { match, Router, browserHistory } from 'react-router';

import App from './App';
import routes from './routes';

const mountNode = document.getElementById('root');

const render = () => {
match({
history: browserHistory,
routes,
}, (error, redirectLocation, renderProps) => {
ReactDOM.render(
<AppContainer>
<Router {...renderProps} />
</AppContainer>,
mountNode,
);
});
};

render();

if (module.hot) {
module.hot.accept('./App', render);
}
7 changes: 7 additions & 0 deletions src/pages/About.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

export default () => (
<div className="about-page">
About
</div>
);
7 changes: 7 additions & 0 deletions src/pages/Home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

export default () => (
<div className="home-page">
Home
</div>
);
13 changes: 13 additions & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { Route, IndexRoute } from 'react-router';

import App from './App';
import Home from './pages/Home';
import About from './pages/About';

export default (
<Route path="/" component={App}>
<IndexRoute component={Home} />
<Route path="about" component={About} />
</Route>
);
42 changes: 42 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const webpack = require('webpack');
const { join, resolve } = require('path');

module.exports = {
entry: {
app: [
'react-hot-loader/patch',
'webpack-hot-middleware/client',
resolve(__dirname, './src/index.js'),
],
vendor: [
'react',
'react-dom',
'react-router',
],
},
output: {
path: resolve(__dirname, 'dist'),
publicPath: '/static/',
filename: '[name].js',
},
context: resolve(__dirname, 'src'),
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
include: join(__dirname, 'src'),
},
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity,
filename: 'vendor.js',
}),
],
};
Loading

0 comments on commit 180a90a

Please sign in to comment.