Skip to content

Commit 7d431a5

Browse files
committedSep 8, 2015
Make hot-reload server work w/ react_on_rails gem
* Need to export App from App.jsx * Removed specifying stage for babel in the loader. * Move exposing React to webpack.common.config.js for page rendering.
1 parent b2c6833 commit 7d431a5

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed
 

‎app/views/pages/index.html.erb

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@
1616
</li>
1717
</ul>
1818
<hr/>
19-
<div id="content">
20-
<%= react_component('App') %>
21-
</div>
19+
<%= react_component('App', {}, prerender: false) %>

‎client/assets/javascripts/App.jsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import { Provider } from 'react-redux';
44
import CommentScreen from './components/CommentScreen';
55
import CommentStore from './stores/CommentStore';
66

7-
window.App = () => {
7+
const App = () => {
88
const reactComponent = (
99
<Provider store={CommentStore}>
1010
{() => <CommentScreen />}
1111
</Provider>
1212
);
1313
return reactComponent;
1414
};
15+
16+
window.App = App;
17+
18+
// Export is needed for the hot reload server
19+
export default App;

‎client/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
</head>
77
<body>
88
<div id="content"></div>
9+
<script>
10+
React.render(App(), document.getElementById('content'));
11+
</script>
912
</body>
1013
</html>

‎client/webpack.common.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ module.exports = {
2020
extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx', '.scss', '.css', 'config.js'],
2121
},
2222
module: {
23-
loaders: [],
23+
loaders: [
24+
// React is necessary for the client rendering:
25+
{test: require.resolve('react'), loader: 'expose?React'}
26+
],
2427
},
2528
};

‎client/webpack.hot.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ config.resolve.root.push(path.join(__dirname, 'assets/stylesheets'));
2727

2828
// All the styling loaders only apply to hot-reload, not rails
2929
config.module.loaders.push(
30-
{test: /\.jsx?$/, loaders: ['react-hot', 'babel?stage=0'], exclude: /node_modules/},
30+
{test: /\.jsx?$/, loaders: ['react-hot', 'babel'], exclude: /node_modules/},
3131
{test: /\.css$/, loader: 'style-loader!css-loader'},
3232
{
3333
test: /\.scss$/,

‎client/webpack.rails.config.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@ config.entry.push('./scripts/rails_only');
2020
// See webpack.common.config for adding modules common to both the webpack dev server and rails
2121

2222
config.module.loaders.push(
23-
{test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader?stage=0'},
23+
{test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader'},
2424

2525
// Next 2 lines expose jQuery and $ to any JavaScript files loaded after client-bundle.js
2626
// in the Rails Asset Pipeline. Thus, load this one prior.
2727
{test: require.resolve('jquery'), loader: 'expose?jQuery'},
28-
{test: require.resolve('jquery'), loader: 'expose?$'},
29-
30-
// React is necessary for the client rendering:
31-
{test: require.resolve('react'), loader: 'expose?React'}
28+
{test: require.resolve('jquery'), loader: 'expose?$'}
3229
);
3330
module.exports = config;
3431

0 commit comments

Comments
 (0)
Please sign in to comment.