Skip to content

Commit 001a3ae

Browse files
kaizencodesjustin808
authored andcommitted
Update to Webpack v2 and Yarn (shakacode#336) (shakacode#367)
- Replaced npm calls to yarn - updated package.json to webpack and all dependencies - updated config files to use webpack2 syntax - updated docs - updated travis config for yarn
1 parent 555ee4e commit 001a3ae

21 files changed

+6232
-5994
lines changed

Diff for: .travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ install:
2727
- chromedriver-update
2828
- nvm install stable && nvm alias default stable
2929
- npm install npm@latest -g
30+
- npm install -g yarn
3031
- npm --version
3132
- npm install
3233
- rake react_on_rails:locale

Diff for: Procfile.dev

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
rails: REACT_ON_RAILS_ENV=HOT rails s -b 0.0.0.0
88

99
# Run the hot reload server for client development
10-
hot-assets: sh -c 'rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && HOT_RAILS_PORT=3500 npm run hot-assets'
10+
hot-assets: sh -c 'rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && HOT_RAILS_PORT=3500 yarn run hot-assets'
1111

1212
# Render static client assets
13-
rails-static-client-assets: sh -c 'npm run build:dev:client'
13+
rails-static-client-assets: sh -c 'yarn run build:dev:client'
1414

1515
# Render static client assets. Remove if not server rendering
16-
rails-static-server-assets: sh -c 'npm run build:dev:server'
16+
rails-static-server-assets: sh -c 'yarn run build:dev:server'

Diff for: Procfile.express

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
# 3. React on Rails does not have a shared_store JS rendering:
1212
# https://github.com/shakacode/react_on_rails/issues/504
1313

14-
express: sh -c 'HOT_PORT=4000 npm start'
14+
express: sh -c 'HOT_PORT=4000 yarn start'

Diff for: Procfile.hot

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
rails: REACT_ON_RAILS_ENV=HOT rails s -b 0.0.0.0
77

88
# Run the hot reload server for client development
9-
hot-assets: sh -c 'rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && HOT_RAILS_PORT=3500 npm run hot-assets'
9+
hot-assets: sh -c 'rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && HOT_RAILS_PORT=3500 yarn run hot-assets'
1010

1111
# Keep the JS fresh for server rendering. Remove if not server rendering
12-
rails-server-assets: sh -c 'npm run build:dev:server'
12+
rails-server-assets: sh -c 'yarn run build:dev:server'

Diff for: Procfile.spec

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# in rails_helper.rb.
44

55
# Build client assets, watching for changes.
6-
rails-client-assets: sh -c 'bundle exec rake react_on_rails:locale && npm run build:dev:client'
6+
rails-client-assets: sh -c 'bundle exec rake react_on_rails:locale && yarn run build:dev:client'
77

88
# Build server assets, watching for changes. Remove if not server rendering.
9-
rails-server-assets: sh -c 'npm run build:dev:server'
9+
rails-server-assets: sh -c 'yarn run build:dev:server'

Diff for: Procfile.static

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
rails: REACT_ON_RAILS_ENV= rails s -b 0.0.0.0
33

44
# Build client assets, watching for changes.
5-
rails-client-assets: rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && npm run build:dev:client
5+
rails-client-assets: rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && yarn run build:dev:client
66

77
# Build server assets, watching for changes. Remove if not server rendering.
8-
rails-server-assets: npm run build:dev:server
8+
rails-server-assets: yarn run build:dev:server

Diff for: Procfile.static.trace

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
rails: TRACE_REACT_ON_RAILS=TRUE rails s -b 0.0.0.0
33

44
# Build client assets, watching for changes.
5-
rails-client-assets: bundle exec rake react_on_rails:locale && npm run build:dev:client
5+
rails-client-assets: bundle exec rake react_on_rails:locale && yarn run build:dev:client
66

77
# Build server assets, watching for changes. Remove if not server rendering.
8-
rails-server-assets: npm run build:dev:server
8+
rails-server-assets: yarn run build:dev:server

Diff for: README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Codeship Build Status](https://codeship.com/projects/287b26d0-0c05-0133-7a33-02e67aca5f06/status?branch=master)](https://app.codeship.com/projects/90975) [![Build Status](https://travis-ci.org/shakacode/react-webpack-rails-tutorial.svg?branch=code_coverage-linting)](https://travis-ci.org/shakacode/react-webpack-rails-tutorial) [![Dependency Status](https://gemnasium.com/shakacode/react-webpack-rails-tutorial.svg)](https://gemnasium.com/shakacode/react-webpack-rails-tutorial) [![Code Climate](https://codeclimate.com/github/shakacode/react-webpack-rails-tutorial/badges/gpa.svg)](https://codeclimate.com/github/shakacode/react-webpack-rails-tutorial) [![Coverage Status](https://coveralls.io/repos/shakacode/react-webpack-rails-tutorial/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react-webpack-rails-tutorial?branch=master)
22

3-
Aloha from Justin Gordon ([bio](http://www.railsonmaui.com/about)) and the [ShakaCode](http://www.shakacode.com) Team! We're actively looking for new projects involving React, React-Native, and Rails. Please [contact me](mailto:[email protected]) if we could potentially help you in any way. Besides consulting on bigger projects, [ShakaCode](http://www.shakacode.com) is doing ScreenHero plus Slack/Github based coaching for React on Rails. See our blog post [Can ShakaCode Help You?](https://blog.shakacode.com/can-shakacode-help-you-4a5b1e5a8a63#.jex6tg9w9) for more information.
3+
Aloha from Justin Gordon ([bio](http://www.railsonmaui.com/about)) and the [ShakaCode](http://www.shakacode.com) Team! We're actively looking for new projects involving React, React-Native, and Rails. Please [contact me](mailto:[email protected]) if we could potentially help you in any way. Besides consulting on bigger projects, [ShakaCode](http://www.shakacode.com) is doing ScreenHero plus Slack/Github based coaching for React on Rails. See our blog post [Can ShakaCode Help You?](https://blog.shakacode.com/can-shakacode-help-you-4a5b1e5a8a63#.jex6tg9w9) for more information.
44

55
I'm offering a free half-hour project consultation, on anything from React on Rails to any aspect of web application development for both consumer and enterprise products. In addition to React.js and Rails, we're doing React-Native iOS and Android apps!
66

@@ -26,7 +26,7 @@ Please [Subscribe](https://app.mailerlite.com/webforms/landing/l1d9x5) to keep i
2626
**[React on Rails](https://github.com/shakacode/react_on_rails)** is ShakaCode's flagship product. We want to make sure you're aware of it!
2727

2828
### Testimonials
29-
From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), January 30, 2017:
29+
From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), January 30, 2017:
3030
![2017-01-30_11-33-59](https://cloud.githubusercontent.com/assets/1118459/22443635/b3549fb4-e6e3-11e6-8ea2-6f589dc93ed3.png)
3131

3232
For more testimonials, see [Live Projects](https://github.com/shakacode/react_on_rails/blob/master/PROJECTS.md) and [Kudos](https://github.com/shakacode/react_on_rails/blob/master/KUDOS.md).
@@ -120,7 +120,8 @@ See package.json and Gemfile for versions
120120
1. Check that you have Postgres installed. Run `which postgres` to check. Use 9.4 or greater.
121121
1. Check that you have `qmake` installed. Run `which qmake` to check. If missing, follow these instructions: [Installing Qt and compiling capybara-webkit](https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit)
122122
1. `bundle install`
123-
1. `npm install`
123+
1. `npm install -g yarn`
124+
1. `yarn`
124125
1. `rake db:setup`
125126
1. `foreman start -f Procfile.hot`
126127
1. Open a browser tab to http://localhost:3000 for the Rails app example with HOT RELOADING
@@ -162,7 +163,7 @@ Save a change to a JSX file and see it update immediately in the browser! Note,
162163
```
163164
+ **Development Mode**: Two flavors: Hot reloading assets (JavaScript & CSS) and Static loading.
164165
+ **Hot Loading**: We modify the URL in [application.html.erb](app/views/layouts/application.html.erb) based on whether or not we're in production mode using the helpers `env_stylesheet_link_tag` and `env_javascript_include_tag`. *Development mode* uses the Webpack Dev server running on port 3500. Other modes (production/test) use precompiled files. See `Procfile.hot`. `Procfile.dev` also starts this mode. Note, *you don't have to refresh a Rails web page to view changes to JavaScript or CSS*.
165-
166+
166167
+ **Static Loading**: This uses webpack to create physical files of the assets, both JavaScript and CSS. This is essentially what we had before we enabled *Hot Loading*. You have to *refresh* the page to see changes to JavaScript or CSS. See `Procfile.static`. It is important to note that tests will use the same statically generated files.
167168
168169
+ Note, the following view helpers do the magic to make this work:
@@ -274,5 +275,3 @@ We're offering a free half-hour project consultation, on anything from React on
274275
Whether you have a new project or need help on an existing project, feel free to contact me directly at [[email protected]](mailto:[email protected]) and thanks in advance for any referrals!
275276

276277
Your support keeps this project going.
277-
278-

Diff for: client/README.md

+13-27
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,39 @@ It also includes many eslint defaults that the AirBnb eslint does not include.
1818
Running linter:
1919
===========================
2020

21-
Soon to be in gulpfile....but gulp-eslint depends on eslint depends on
21+
Soon to be in gulpfile....but gulp-eslint depends on eslint depends on
2222

2323
```
2424
"eslint-plugin-react": "^2.0.2",
2525
```
2626

27-
So don't use `npm run gulp lint` yet.
27+
So don't use `yarn run gulp lint` yet.
2828

29-
For now:
29+
For now:
3030

3131
bin/lint
32-
32+
3333
Or (from either top level or within `client` directory)
3434

35-
npm run lint
36-
37-
35+
yarn run lint
36+
37+
3838
Updating Node Dependencies
3939
===========================
4040

4141
```
42-
npm install -g npm-check-updates
42+
yarn global add npm-check-updates
4343
```
44-
44+
4545
Then run this to update the dependencies (starting at the top level).
4646

4747
```
4848
# Make sure you are in the top directory, then run:
49-
cd client
50-
rm npm-shrinkwrap.json
51-
npm-check-updates -u
52-
npm install
53-
npm prune
54-
npm shrinkwrap
49+
cd client
50+
ncu -u
51+
yarn upgrade
5552
```
5653

57-
Then confirm that the hot reload server and the rails server both work fine. You
58-
may have to delete `node_modules` and `npm-shrinkwrap.json` and then run `npm
59-
shrinkwrap`.
60-
61-
Note: `npm prune` is required before running `npm shrinkwrap` to remove dependencies that are no longer needed after doing updates.
62-
63-
6454
Adding Node Modules
6555
=====================================
6656
Suppose you want to add a dependency to "module_name"....
@@ -72,9 +62,5 @@ Before you do so, consider:
7262

7363
```bash
7464
cd client
75-
npm install --save module_name@version
76-
# or
77-
# npm install --save_dev module_name@version
78-
rm npm-shrinkwrap.json
79-
npm shrinkwrap
65+
yarn add module_name@version
8066
```

0 commit comments

Comments
 (0)