Skip to content

Commit 1477ba6

Browse files
committed
Update libraries and JSX for current versions 1/23/2015
* Required a few JSX changes. * Don't use import for commonjs modules * key changed to eventKey for NavItem * Use different names for the the native input HTML elements compared to the react-bootstrap ones * Could not update the sass-loader without errors * Moved all Sass related parts of webpack to the webpack.hot.config.js as Rails version does not use the Webpack sass handlers. * Changed webpack.rails.config.js so that the loader for JSX does not use react-hot * Added the woff2 pattern for the file loader. * Changed from React.renderComponent to React.render in example.jsx.
1 parent 0ce8594 commit 1477ba6

8 files changed

+300
-741
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ buildpack:
175175
heroku config:add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
176176
```
177177

178-
This runs the two buildpacks in the `.buildpacks` file.
178+
This runs the two buildpacks in the `.buildpacks` directory.
179179

180180
Also make sure you are running the latest heroku stack, cedar-14, to avoid running
181181
into the [following issue](https://github.com/sass/node-sass/issues/467#issuecomment-61729195).
@@ -188,3 +188,14 @@ To deploy the app on Heroku:
188188
```
189189
git push heroku master
190190
```
191+
192+
# Update Node Modules
193+
```
194+
npm-check-updates -u
195+
npm-install
196+
```
197+
Then confirm that the hot reload server and the rails server both work fine. You
198+
may have to delete `node_modules` and `npm-shrinkwrap.json` and then run `npm
199+
shrinkwrap`.
200+
201+

npm-shrinkwrap.json

+220-681
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+18-19
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,31 @@
77
"node": "0.10.32"
88
},
99
"dependencies": {
10-
"body-parser": "^1.9.0",
11-
"bootstrap-sass": "^3.3.1",
12-
"bootstrap-sass-loader": "0.0.5",
13-
"bootstrap-webpack": "*",
1410
"es6-loader": "^0.2.0",
15-
"express": "^4.9.8",
11+
"body-parser": "^1.10.2",
1612
"imports-loader": "^0.6.3",
17-
"jquery": "^2.1.1",
18-
"jsx-loader": "^0.11.2",
19-
"loader-utils": "^0.2.2",
20-
"marked": "^0.3.2",
21-
"react": "^0.11.2",
22-
"react-bootstrap": "^0.12.0",
23-
"sleep": "1.1.8",
24-
"webpack": "^1.4.8"
13+
"jquery": "^2.1.3",
14+
"jsx-loader": "^0.12.2",
15+
"loader-utils": "^0.2.6",
16+
"marked": "^0.3.3",
17+
"react": "^0.12.2",
18+
"react-bootstrap": "^0.13.3",
19+
"sleep": "^1.2.0",
20+
"webpack": "^1.5.3"
2521
},
2622
"devDependencies": {
27-
"css-loader": "^0.9.0",
28-
"expose-loader": "^0.5.3",
29-
"extract-text-webpack-plugin": "^0.3.3",
23+
"express": "^4.11.1",
24+
"bootstrap-sass": "^3.3.3",
25+
"bootstrap-sass-loader": "0.0.6",
26+
"css-loader": "^0.9.1",
27+
"expose-loader": "^0.6.0",
28+
"extract-text-webpack-plugin": "^0.3.8",
3029
"file-loader": "^0.8.1",
31-
"react-hot-loader": "^0.5.0",
30+
"react-hot-loader": "^1.1.3",
3231
"sass-loader": "^0.2.0",
33-
"style-loader": "^0.8.1",
32+
"style-loader": "^0.8.3",
3433
"url-loader": "^0.5.5",
35-
"webpack-dev-server": "^1.6.5"
34+
"webpack-dev-server": "^1.7.0"
3635
},
3736
"scripts": {
3837
"test": "echo \"Error: no test specified\" && exit 1",

webpack/assets/javascripts/CommentBox.jsx

+26-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
/** @jsx React.DOM */
2-
31
var $ = require('jquery');
4-
module React from 'react/addons';
2+
var React = require('react/addons');
53

64
// Next line is necessary for exposing React to browser for
75
// the React Developer Tools: http://facebook.github.io/react/blog/2014/01/02/react-chrome-developer-tools.html
@@ -34,6 +32,7 @@ var CommentBox = React.createClass({
3432
logError: function(xhr, status, err) {
3533
console.error(`Error loading comments from server!\nURL is ${this.props.url}\nstatus is ${status}\nerr is ${err.toString()}`);
3634
},
35+
3736
loadCommentsFromServer: function() {
3837
$.ajax({
3938
url: this.props.url,
@@ -42,6 +41,7 @@ var CommentBox = React.createClass({
4241
}, this.logError);
4342
},
4443
emptyFormData: { author: "", text: "" },
44+
4545
handleCommentSubmit: function() {
4646
// `setState` accepts a callback. To avoid (improbable) race condition,
4747
// `we'll send the ajax request right after we optimistically set the new
@@ -61,13 +61,15 @@ var CommentBox = React.createClass({
6161
this.setState({ajaxSending: false});
6262
});
6363
},
64+
6465
getInitialState: function() {
6566
return {
6667
data: [],
6768
formData: this.emptyFormData,
6869
ajaxSending: false
6970
};
7071
},
72+
7173
componentDidMount: function() {
7274
this.loadCommentsFromServer();
7375
setInterval(this.loadCommentsFromServer, this.props.pollInterval);
@@ -78,6 +80,7 @@ var CommentBox = React.createClass({
7880
formData: obj
7981
})
8082
},
83+
8184
render: function() {
8285
return (
8386
<div className="commentBox container">
@@ -116,31 +119,36 @@ var CommentForm = React.createClass({
116119
formMode: 0
117120
};
118121
},
122+
119123
handleSubmit: function(e) {
120124
e.preventDefault();
121125
this.props.onCommentSubmit();
122126
return;
123127
},
128+
124129
handleSelect: function(selectedKey) {
125130
this.setState({ formMode: selectedKey });
126131
},
132+
127133
handleChange: function() {
128134
// This could also be done using ReactLink:
129135
// http://facebook.github.io/react/docs/two-way-binding-helpers.html
130-
var props;
131-
if (this.props.formMode == 2) {
132-
props = {
133-
author: this.refs.author.getDOMNode().value,
134-
text: this.refs.text.getDOMNode().value
135-
}
136-
} else {
137-
props = {
136+
var obj;
137+
if (this.state.formMode < 2) {
138+
obj = {
138139
author: this.refs.author.getValue(),
139140
text: this.refs.text.getValue()
140141
}
142+
} else {
143+
// This is different because the input is a native HTML element rather than a React element
144+
obj = {
145+
author: this.refs.inlineAuthor.getDOMNode().value,
146+
text: this.refs.inlineText.getDOMNode().value
147+
}
141148
}
142-
this.props.onChange(props);
149+
this.props.onChange(obj);
143150
},
151+
144152
formHorizontal: function() {
145153
return (
146154
<div><hr/>
@@ -151,6 +159,7 @@ var CommentForm = React.createClass({
151159
</form></div>
152160
);
153161
},
162+
154163
formStacked: function() {
155164
return (
156165
<div><hr/>
@@ -168,10 +177,10 @@ var CommentForm = React.createClass({
168177
<Input label="Inline Form" wrapperClassName="wrapper">
169178
<Row>
170179
<Col xs={3}>
171-
<input type="text" className="form-control" placeholder="Your Name" ref="author" value={this.props.formData.author} onChange={this.handleChange} disabled={this.props.ajaxSending} />
180+
<input type="text" className="form-control" placeholder="Your Name" ref="inlineAuthor" value={this.props.formData.author} onChange={this.handleChange} disabled={this.props.ajaxSending} />
172181
</Col>
173182
<Col xs={8}>
174-
<input type="text" className="form-control" placeholder="Say something..." ref="text" value={this.props.formData.text} onChange={this.handleChange} disabled={this.props.ajaxSending} />
183+
<input type="text" className="form-control" placeholder="Say something..." ref="inlineText" value={this.props.formData.text} onChange={this.handleChange} disabled={this.props.ajaxSending} />
175184
</Col>
176185
<Col xs={1}>
177186
<input type="submit" className="btn btn-primary" value="Post" disabled={this.props.ajaxSending} />
@@ -196,9 +205,9 @@ var CommentForm = React.createClass({
196205
return (
197206
<div>
198207
<Nav bsStyle="pills" activeKey={this.state.formMode} onSelect={this.handleSelect}>
199-
<NavItem key={0}>Horizontal Form</NavItem>
200-
<NavItem key={1}>Stacked Form</NavItem>
201-
<NavItem key={2}>Inline Form</NavItem>
208+
<NavItem eventKey={0}>Horizontal Form</NavItem>
209+
<NavItem eventKey={1}>Stacked Form</NavItem>
210+
<NavItem eventKey={2}>Inline Form</NavItem>
202211
</Nav>
203212
{inputForm}
204213
</div>

webpack/assets/javascripts/example.jsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
/** @jsx React.DOM */
1+
var React = require('react/addons');
22

3-
module React from 'react';
43
import { CommentBox } from './CommentBox';
54

65
var $ = require('jquery');
76

87
var render = () => {
98
if ($("#content").length > 0) {
10-
React.renderComponent(
9+
React.render(
1110
<div>
1211
<CommentBox url="comments.json" pollInterval={2000} />
1312
<div className="container">
@@ -22,7 +21,7 @@ var render = () => {
2221
document.getElementById('content')
2322
);
2423
}
25-
}
24+
};
2625

2726
$(function() {
2827
render();

webpack/webpack.common.config.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@ module.exports = {
1717
},
1818
module: {
1919
loaders: [
20-
{ test: /\.css$/, loader: "style-loader!css-loader" },
21-
{ test: /\.scss$/, loader: "style!css!sass?outputStyle=expanded&imagePath=/assets/images"},
22-
23-
// The url-loader uses DataUrls. The file-loader emits files.
24-
{ test: /\.woff$/, loader: "url-loader?limit=10000&minetype=application/font-woff" },
25-
{ test: /\.ttf$/, loader: "file-loader" },
26-
{ test: /\.eot$/, loader: "file-loader" },
27-
{ test: /\.svg$/, loader: "file-loader" }
20+
{ test: require.resolve("react"), loader: "expose?React" }
2821
]
2922
}
3023
};

webpack/webpack.hot.config.js

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Run like this:
22
// cd webpack && node server.js
33

4+
var path = require("path");
45
var config = require("./webpack.common.config");
56
var webpack = require("webpack");
67

@@ -18,4 +19,19 @@ config.module.loaders.push(
1819
);
1920
config.plugins = [ new webpack.HotModuleReplacementPlugin() ];
2021
config.devtool = "eval-source-map";
22+
23+
// All the styling loaders only apply to hot-reload, not rails
24+
config.module.loaders.push(
25+
{ test: /\.jsx$/, loaders: ["react-hot", "es6", "jsx?harmony"] },
26+
{ test: /\.css$/, loader: "style-loader!css-loader" },
27+
{ test: /\.scss$/, loader: "style!css!sass?outputStyle=expanded&imagePath=/assets/images&includePaths[]=" +
28+
path.resolve(__dirname, "./assets/stylesheets")},
29+
30+
// The url-loader uses DataUrls. The file-loader emits files.
31+
{ test: /\.woff$/, loader: "url-loader?limit=10000&minetype=application/font-woff" },
32+
{ test: /\.woff2$/, loader: "url-loader?limit=10000&minetype=application/font-woff" },
33+
{ test: /\.ttf$/, loader: "file-loader" },
34+
{ test: /\.eot$/, loader: "file-loader" },
35+
{ test: /\.svg$/, loader: "file-loader" });
36+
2137
module.exports = config;

webpack/webpack.rails.config.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// cd webpack && $(npm bin)/webpack -w --config webpack.rails.config.js
33
// Note that Foreman (Procfile.dev) has also been configured to take care of this.
44

5+
// NOTE: All style sheets handled by the asset pipeline in rails
6+
57
var config = require("./webpack.common.config");
68

79
config.entry.push("./scripts/rails_only"); // rails specific assets
@@ -10,26 +12,17 @@ config.output = { filename: "webpack-bundle.js",
1012
config.externals = { jquery: "var jQuery" }; // load jQuery from cdn or rails asset pipeline
1113
config.module.loaders.push(
1214
{ test: /\.jsx$/, loaders: ["es6", "jsx?harmony"] },
13-
{ test: /\.scss$/, loader: "style!css!sass?outputStyle=expanded&imagePath=/assets/images"},
1415
// Next 2 lines expose jQuery and $ to any JavaScript files loaded after webpack-bundle.js
1516
// in the Rails Asset Pipeline. Thus, load this one prior.
1617
{ test: require.resolve("jquery"), loader: "expose?jQuery" },
1718
{ test: require.resolve("jquery"), loader: "expose?$" }
1819
);
20+
module.exports = config;
1921

2022
var devBuild = (typeof process.env["BUILDPACK_URL"]) === "undefined";
2123
if (devBuild) {
2224
console.log("Webpack dev build for Rails");
23-
config.module.loaders.push(
24-
{ test: require.resolve("react"), loader: "expose?React" },
25-
{ test: /\.jsx$/, loaders: ["react-hot", "es6", "jsx?harmony"] }
26-
);
27-
config.devtool = "eval-source-map";
25+
module.exports.devtool = "eval-source-map";
2826
} else {
2927
console.log("Webpack production build for Rails");
30-
config.module.loaders.push(
31-
{ test: /\.jsx$/, loaders: ["es6", "jsx?harmony"] }
32-
);
3328
}
34-
35-
module.exports = config;

0 commit comments

Comments
 (0)