Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Hot Loader 3.0 beta demo #61

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c423415
React Hot Loader 3.0 demo
gaearon Apr 17, 2016
5d5175b
Use Babel
gaearon Apr 18, 2016
afa4aee
Bump version!
gaearon Apr 18, 2016
691fe11
Bump version
gaearon Apr 18, 2016
7f8903b
Bump the version
gaearon Apr 28, 2016
b52c727
Bump to 3.0.0-beta.0
gaearon Apr 30, 2016
f134ff3
Bump version
gaearon May 2, 2016
febf956
changed the regex expression to handle .jsx files (#83)
gfantom Nov 1, 2016
dfeb37b
Use webpack middleware
bradleyboy May 20, 2016
f764530
Add express, remove webpack dev server
bradleyboy May 20, 2016
5c76efd
Formatting
bradleyboy May 20, 2016
372080f
update dependencies and add yarn.lock
calesce Nov 3, 2016
a26a653
add OccurrenceOrder and NoErrors webpack plugins
calesce Nov 20, 2016
9089b6b
use cheap-module-eval-source-map option for source maps
calesce Nov 20, 2016
9609a8e
use cheap-module-source-map
calesce Nov 21, 2016
437dc6a
Updated dependencies
petertrotman Jan 25, 2017
314c024
Updated .babelrc and webpack.config.js
petertrotman Jan 25, 2017
6811627
Updated
petertrotman Jan 25, 2017
19d3594
Resolved inconsistencies with webpack's guide setup and original boil…
petertrotman Jan 25, 2017
59281e4
Readded yarn.lock file with updated dependencies
petertrotman Jan 25, 2017
abe4763
Updated README with citation to webpack guide and removed reference t…
petertrotman Jan 25, 2017
c78530f
removed .jshintrc
calesce Jan 25, 2017
26938f2
update license and fix some formatting
calesce Jan 25, 2017
43f80ee
Readded eslint and updated yarn.lock
petertrotman Jan 26, 2017
d6891f2
Fixed missing eslint dependency and updated yarn.lock file
petertrotman Jan 26, 2017
92cb506
Merge branch 'next' into next
calesce Jan 26, 2017
8a05c0d
Merge pull request #111 from petertrotman/next
calesce Jan 26, 2017
949277a
document known WebStorm file-watching issue
calesce Jan 26, 2017
677a4d6
Ensure initial render
petertrotman Jan 26, 2017
a2d489d
Add basic build script
cookpete Feb 20, 2017
530fb8f
update yarn.lock
calesce Feb 26, 2017
8ebffda
update README
vikr01 Oct 5, 2018
4e51cf7
Merge pull request #141 from vikr01/next
theKashey Oct 5, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"presets": ["es2015", "stage-0", "react"]
"presets": ["es2015", "stage-0", "react"],
"plugins": ["react-hot-loader/babel"]
}
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@
"homepage": "https://github.com/gaearon/react-hot-boilerplate",
"devDependencies": {
"babel-core": "^6.0.20",
"babel-eslint": "^4.1.3",
"babel-eslint": "^7.1.0",
"babel-loader": "^6.0.1",
"babel-preset-es2015": "^6.0.15",
"babel-preset-react": "^6.0.15",
"babel-preset-stage-0": "^6.0.15",
"eslint": "^1.10.3",
"eslint-plugin-react": "^3.6.2",
"react-hot-loader": "^1.3.0",
"eslint": "^3.9.1",
"eslint-plugin-react": "^6.5.0",
"express": "^4.13.4",
"webpack": "^1.12.2",
"webpack-dev-server": "^1.12.1"
"webpack-dev-middleware": "^1.6.1",
"webpack-hot-middleware": "^2.10.0"
},
"dependencies": {
"react": "^0.14.6",
"react-dom": "^0.14.6"
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-hot-loader": "^3.0.0-beta.6"
}
}
25 changes: 19 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
var path = require('path');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var express = require('express');
var devMiddleware = require('webpack-dev-middleware');
var hotMiddleware = require('webpack-hot-middleware');
var config = require('./webpack.config');

new WebpackDevServer(webpack(config), {
var app = express();
var compiler = webpack(config);

app.use(devMiddleware(compiler, {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true
}).listen(3000, 'localhost', function (err, result) {
historyApiFallback: true,
}));

app.use(hotMiddleware(compiler));

app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'index.html'));
});

app.listen(3000, function (err) {
if (err) {
return console.log(err);
return console.error(err);
}

console.log('Listening at http://localhost:3000/');
Expand Down
13 changes: 12 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import React, { Component } from 'react';
import Layout from './Layout';
import Counter from './Counter';

// If you use React Router, make this component
// render <Router> with your routes. Currently,
// only synchronous routes are hot reloaded, and
// you will see a warning from <Router> on every reload.
// You can ignore this warning. For details, see:
// https://github.com/reactjs/react-router/issues/2182

export default class App extends Component {
render() {
return (
<h1>Hello, world.</h1>
<Layout>
<Counter />
</Layout>
);
}
}
29 changes: 29 additions & 0 deletions src/Counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { Component } from 'react';

export default class Counter extends Component {
constructor(props) {
super(props);
this.state = { counter: 0 };
}

componentDidMount() {
this.interval = setInterval(this.tick.bind(this), 1000);
}

tick() {
this.setState({
counter: this.state.counter + 1
});
}

componentWillUnmount() {
clearInterval(this.interval);
}

render() {
return (
<h2>Counter: {this.state.counter}</h2>
);
}
}

10 changes: 10 additions & 0 deletions src/Layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

export default function Layout({ children }) {
return (
<div>
<h1>Hello, world!</h1>
{children}
</div>
)
}
23 changes: 22 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import { AppContainer } from 'react-hot-loader';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));
const rootEl = document.getElementById('root');
ReactDOM.render(
<AppContainer>
<App />
</AppContainer>,
rootEl
);

if (module.hot) {
module.hot.accept('./App', () => {
// If you use Webpack 2 in ES modules mode, you can
// use <App /> here rather than require() a <NextApp />.
const NextApp = require('./App').default;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up for anyone using babel-plugin-add-module-exports, remove the .default. i.e.

const NextApp = require('./App');

ReactDOM.render(
<AppContainer>
<NextApp />
</AppContainer>,
rootEl
);
});
}
14 changes: 8 additions & 6 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ var path = require('path');
var webpack = require('webpack');

module.exports = {
devtool: 'eval',
devtool: 'cheap-module-eval-source-map',
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend to remove -eval here, it messes with breakpoints.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I didn't know that (I'm a console-logger), have a link?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A link to what? No specific issue, just Chrome debugger getting messed up.
I recommend 'cheap-module-source-map' instead.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like webpack/webpack#2145 might be the issue.

Copy link

@Jessidhia Jessidhia Nov 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breakpoints (appear to) work with -eval, but only if they're not sync. Chrome only loads the source maps after it finishes running the eval call itself.

But it still mangles the stack traces 😢

entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'react-hot-loader/patch',
'webpack-hot-middleware/client',
'./src/index'
],
output: {
Expand All @@ -14,12 +14,14 @@ module.exports = {
publicPath: '/static/'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
],
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
test: /\.jsx?$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
}]
}
Expand Down
Loading