react_on_rails 8.0.0.beta.2 → 8.0.0.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/Gemfile +15 -5
- data/KUDOS.md +12 -4
- data/PROJECTS.md +1 -0
- data/README.md +4 -3
- data/app/helpers/react_on_rails_helper.rb +15 -18
- data/docs/additional-reading/heroku-deployment.md +0 -1
- data/docs/additional-reading/images.md +46 -23
- data/docs/additional-reading/server-rendering-tips.md +3 -3
- data/docs/tutorial.md +12 -11
- data/lib/generators/react_on_rails/base_generator.rb +60 -3
- data/lib/generators/react_on_rails/dev_tests_generator.rb +14 -3
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +1 -6
- data/lib/generators/react_on_rails/templates/base/base/client/webpack.config.js +27 -19
- data/lib/generators/react_on_rails/templates/base/base/config/webpacker_lite.yml +27 -0
- data/lib/generators/react_on_rails/templates/base/base/package.json.tt +3 -9
- data/lib/react_on_rails/engine.rb +2 -0
- data/lib/react_on_rails/server_rendering_pool/exec.rb +27 -28
- data/lib/react_on_rails/test_helper.rb +1 -2
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +2 -2
- data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +7 -2
- data/lib/react_on_rails/utils.rb +20 -3
- data/lib/react_on_rails/version.rb +1 -1
- data/package.json +1 -1
- data/rakelib/dummy_apps.rake +1 -1
- data/rakelib/examples.rake +1 -1
- data/rakelib/lint.rake +1 -1
- data/rakelib/release.rake +2 -2
- data/rakelib/run_rspec.rake +11 -14
- data/react_on_rails.gemspec +6 -5
- data/webpackConfigLoader.js +84 -15
- metadata +3 -4
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.server.yml +0 -9
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/paths.yml +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ac36fba9ba57940b308785f01d5a5033f0494cb
|
4
|
+
data.tar.gz: 05b6edf7d7a0f99b493d3a115479cd76ba4d6780
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 190817a80ba2194d7bca71ef73f53d9d241bb442cd3e26c001301bf92790a3a50abe83155cbc78b6e649e0a76a39b8501a9c049805ce67db9c657ca4a7e88b17
|
7
|
+
data.tar.gz: 6b3cf199fb90fac4d9484c20774e10e52e2ea76c2702b2e269e569d5bd19ef92064fe94baf40055cbdd89a1a18a7bec5b01f99dc8efde03984f7ff9151b8653e
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,14 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
|
|
6
6
|
## [Unreleased]
|
7
7
|
*Please add entries here for your pull requests.*
|
8
8
|
|
9
|
+
## Changed
|
10
|
+
- Logging no longer occurs when trace is turned to false. [#845](https://github.com/shakacode/react_on_rails/pull/845) by [conturbo](https://github.com/Conturbo)
|
11
|
+
|
12
|
+
## [8.0.0-beta.2] - 2017-05-08
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
Removed unnecessary values in default paths.yml files for generators. [#834](https://github.com/shakacode/react_on_rails/pull/834) by [justin808](https://github.com/justin808).
|
16
|
+
|
9
17
|
## [8.0.0-beta.1] - 2017-05-03
|
10
18
|
|
11
19
|
### Added
|
@@ -575,7 +583,8 @@ Best done with Object destructing:
|
|
575
583
|
##### Fixed
|
576
584
|
- Fix several generator related issues.
|
577
585
|
|
578
|
-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/8.0.0-beta.
|
586
|
+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/8.0.0-beta.2...master
|
587
|
+
[8.0.0-beta.2]: https://github.com/shakacode/react_on_rails/compare/8.0.0-beta.1...8.0.0-beta.2
|
579
588
|
[8.0.0-beta.1]: https://github.com/shakacode/react_on_rails/compare/7.0.4...8.0.0-beta.1
|
580
589
|
[7.0.4]: https://github.com/shakacode/react_on_rails/compare/7.0.3...7.0.4
|
581
590
|
[7.0.3]: https://github.com/shakacode/react_on_rails/compare/7.0.1...7.0.3
|
data/Gemfile
CHANGED
@@ -8,11 +8,11 @@ gemspec
|
|
8
8
|
# bundle install from a single Gemfile. Therefore, all gems that we will need for any dummy/example
|
9
9
|
# app have to be manually added to this file.
|
10
10
|
gem "bootstrap-sass"
|
11
|
-
gem "coffee-rails", "~> 4.1.0"
|
12
11
|
gem "jbuilder", "~> 2.0"
|
13
12
|
gem "jquery-rails"
|
13
|
+
gem "mini_racer"
|
14
14
|
gem "puma"
|
15
|
-
gem "rails", "
|
15
|
+
gem "rails", "5.1.1"
|
16
16
|
gem "rails_12factor"
|
17
17
|
gem "rubocop", "0.47.1", require: false
|
18
18
|
gem "ruby-lint", require: false
|
@@ -21,7 +21,6 @@ gem "scss_lint", require: false
|
|
21
21
|
gem "sdoc", "~> 0.4.0", group: :doc
|
22
22
|
gem "spring"
|
23
23
|
gem "sqlite3"
|
24
|
-
gem "mini_racer"
|
25
24
|
if ENV["ENABLE_TURBOLINKS_2"].nil? || ENV["ENABLE_TURBOLINKS_2"].strip.empty?
|
26
25
|
gem "turbolinks", "~> 5.0"
|
27
26
|
else
|
@@ -31,13 +30,24 @@ gem "uglifier", ">= 2.7.2"
|
|
31
30
|
gem "web-console", "~> 2.0", group: :development
|
32
31
|
|
33
32
|
# below are copied from spec/dummy/Gemfile
|
34
|
-
gem "rspec-rails"
|
35
|
-
gem "rspec-retry"
|
36
33
|
gem "capybara"
|
37
34
|
gem "capybara-screenshot"
|
35
|
+
gem "rspec-rails"
|
36
|
+
gem "rspec-retry"
|
38
37
|
# Trouble installing on Sierra
|
39
38
|
# gem "capybara-webkit"
|
40
39
|
gem "chromedriver-helper"
|
41
40
|
gem "launchy"
|
42
41
|
gem "poltergeist"
|
43
42
|
gem "selenium-webdriver"
|
43
|
+
gem "webpacker_lite"
|
44
|
+
|
45
|
+
################################################################################
|
46
|
+
# Favorite debugging gems
|
47
|
+
gem "pry"
|
48
|
+
gem "pry-byebug"
|
49
|
+
gem "pry-doc"
|
50
|
+
gem "pry-rails"
|
51
|
+
gem "pry-rescue"
|
52
|
+
gem "pry-stack_explorer"
|
53
|
+
################################################################################
|
data/KUDOS.md
CHANGED
@@ -2,17 +2,24 @@ This is a sibling file to [PROJECTS.md](./PROJECTS.md).
|
|
2
2
|
|
3
3
|
I'm looking for quotes on why you like using React on Rails. You might mention any benefits you particularly like and if you've migrated from react-rails. Just click to edit and github will automatically open up a PR. Thanks to everybody that contributes!
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
### May 6, 2017
|
6
|
+
By Email
|
7
|
+
|
8
|
+
![image](https://cloud.githubusercontent.com/assets/1118459/25869348/b1bd27ce-349b-11e7-912c-11d05ab2bf4d.png)
|
9
|
+
|
10
|
+
### April 6, 2017
|
11
|
+
Tyler Swayne on Medium: [Adding react to your node app](https://medium.com/@Tswaynee/adding-react-to-your-node-app-8707c5464b3)
|
7
12
|
|
8
13
|
![2017-04-06_16-11-51](https://cloud.githubusercontent.com/assets/1118459/24786595/75bb2b9c-1afe-11e7-8051-8c9046c4e007.png)
|
9
14
|
|
10
15
|
### March 23, 2017
|
11
16
|
Github issue [#766](https://github.com/shakacode/react_on_rails/issues/766).
|
17
|
+
|
12
18
|
![2017-03-23_17-43-17](https://cloud.githubusercontent.com/assets/1118459/24279884/badab166-0ff0-11e7-87ab-94253f55a3d9.png)
|
13
19
|
|
14
|
-
|
20
|
+
### March 21, 2017
|
15
21
|
Twitter from [@rfc2616](https://twitter.com/rfc2616)
|
22
|
+
|
16
23
|
![2017-03-24_20-20-20](https://cloud.githubusercontent.com/assets/1118459/24319983/7adfd57a-10cf-11e7-9a50-5c23d5d5bcab.png)
|
17
24
|
|
18
25
|
### March 2, 2017
|
@@ -38,7 +45,8 @@ Twitter from [@rfc2616](https://twitter.com/rfc2616)
|
|
38
45
|
https://github.com/shakacode/react_on_rails/pull/591#issuecomment-258685925
|
39
46
|
![2016-11-15_08-36-29](https://cloud.githubusercontent.com/assets/1118459/20318599/ec4882b0-ab0e-11e6-83e2-7f398e2cdf5b.png)
|
40
47
|
|
41
|
-
### October 29, 2016
|
48
|
+
### October 29, 2016
|
49
|
+
by Email
|
42
50
|
![2016-10-29_17-10-25](https://cloud.githubusercontent.com/assets/1118459/20163712/72307a82-a6b3-11e6-9c46-aee526192b23.png)
|
43
51
|
|
44
52
|
### September 11, 2016
|
data/PROJECTS.md
CHANGED
@@ -41,3 +41,4 @@
|
|
41
41
|
* [github.com/Limenius/symfony-react-sandbox](https://github.com/Limenius/symfony-react-sandbox)
|
42
42
|
* [github.com/tswayne/react-helper](https://github.com/tswayne/react-helper)
|
43
43
|
* [github.com/KissKissBankBank/kitten](https://github.com/KissKissBankBank/kitten)
|
44
|
+
* [github.com/sharetribe/sharetribe](https://github.com/sharetribe/sharetribe): Open source marketplace platform.
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/shakacode/react_on_rails.svg?branch=master)](https://travis-ci.org/shakacode/react_on_rails) [![Codeship Status for shakacode/react_on_rails](https://app.codeship.com/projects/cec6c040-971f-0134-488f-0a5146246bd8/status?branch=master)](https://app.codeship.com/projects/187011) [![Dependency Status](https://gemnasium.com/shakacode/react_on_rails.svg)](https://gemnasium.com/shakacode/react_on_rails) [![Gem Version](https://badge.fury.io/rb/react_on_rails.svg)](https://badge.fury.io/rb/react_on_rails) [![npm version](https://badge.fury.io/js/react-on-rails.svg)](https://badge.fury.io/js/react-on-rails) [![Code Climate](https://codeclimate.com/github/shakacode/react_on_rails/badges/gpa.svg)](https://codeclimate.com/github/shakacode/react_on_rails) [![Coverage Status](https://coveralls.io/repos/shakacode/react_on_rails/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react_on_rails?branch=master)
|
2
2
|
|
3
|
-
#### The Docs here on `master` refer to 8.0.0-beta.
|
4
|
-
**[VERSION 8.0.0-beta.
|
3
|
+
#### The Docs here on `master` refer to 8.0.0-beta.2 including support for Webpacker! 7.0.4 docs are [here](https://github.com/shakacode/react_on_rails/tree/7.0.4).
|
4
|
+
* **[VERSION 8.0.0-beta.2](https://rubygems.org/gems/react_on_rails/versions/8.0.0.beta.2)** has shipped with [webpacker_lite](https://github.com/shakacode/webpacker_lite) support! Please try [the 8.0.0-beta.2 beta](https://rubygems.org/gems/react_on_rails/versions/8.0.0.beta.2) and please report issues!
|
5
|
+
* Why did we fork webpacker to make webpacker_lite? Please provide feedback on my draft article: [Webpacker Lite: Why Did We Fork Webpacker?](https://medium.com/@railsonmaui/webpacker-lite-why-did-we-fork-webpacker-ee3305688d66)
|
5
6
|
|
6
7
|
**For a complete example of this gem, see our live demo at [www.reactrails.com](http://www.reactrails.com). ([Source Code](https://github.com/shakacode/react-webpack-rails-tutorial))**
|
7
8
|
|
@@ -15,7 +16,7 @@ Whether you have a new project or need help on an existing project, feel free to
|
|
15
16
|
|
16
17
|
Your support keeps this project going!
|
17
18
|
|
18
|
-
(Want to become a contributor? [Contact us](mailto:contact@shakacode.com) for a Slack room invite and let us know that you want to contribute.)
|
19
|
+
(Want to become a contributor? We're hiring! Want to join a 100% remote-first team? [Contact us](mailto:contact@shakacode.com) for a Slack room invite and let us know that you want to contribute.)
|
19
20
|
|
20
21
|
# Community
|
21
22
|
Please [Subscribe](https://app.mailerlite.com/webforms/landing/l1d9x5) to keep in touch with Justin Gordon and [ShakaCode](http://www.shakacode.com/). I intend to send a monthly summary including announcements of new releases of React on Rails and of our latest [blog articles](https://blog.shakacode.com) and tutorials. Subscribers will also have access to **exclusive content**, including tips and examples.
|
@@ -111,7 +111,7 @@ module ReactOnRailsHelper
|
|
111
111
|
type: "application/json",
|
112
112
|
class: "js-react-on-rails-component",
|
113
113
|
"data-component-name" => options.name,
|
114
|
-
"data-trace" => options.trace,
|
114
|
+
"data-trace" => (options.trace ? true : nil),
|
115
115
|
"data-dom-id" => options.dom_id)
|
116
116
|
|
117
117
|
# Create the HTML rendering part
|
@@ -223,10 +223,9 @@ module ReactOnRailsHelper
|
|
223
223
|
console_log_script = result["consoleLogScript"]
|
224
224
|
raw("#{html}#{replay_console_option(options[:replay_console_option]) ? console_log_script : ''}")
|
225
225
|
rescue ExecJS::ProgramError => err
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
js_code: wrapper_js)
|
226
|
+
raise ReactOnRails::PrerenderError, component_name: "N/A (server_render_js called)",
|
227
|
+
err: err,
|
228
|
+
js_code: wrapper_js
|
230
229
|
# rubocop:enable Style/RaiseArgs
|
231
230
|
end
|
232
231
|
|
@@ -387,24 +386,22 @@ module ReactOnRailsHelper
|
|
387
386
|
|
388
387
|
if result["hasErrors"] && raise_on_prerender_error
|
389
388
|
# We caught this exception on our backtrace handler
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
console_messages: result["consoleReplayScript"])
|
389
|
+
raise ReactOnRails::PrerenderError, component_name: react_component_name,
|
390
|
+
# Sanitize as this might be browser logged
|
391
|
+
props: sanitized_props_string(props),
|
392
|
+
err: nil,
|
393
|
+
js_code: wrapper_js,
|
394
|
+
console_messages: result["consoleReplayScript"]
|
397
395
|
# rubocop:enable Style/RaiseArgs
|
398
396
|
end
|
399
397
|
result
|
400
398
|
rescue ExecJS::ProgramError => err
|
401
399
|
# This error came from execJs
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
js_code: wrapper_js)
|
400
|
+
raise ReactOnRails::PrerenderError, component_name: react_component_name,
|
401
|
+
# Sanitize as this might be browser logged
|
402
|
+
props: sanitized_props_string(props),
|
403
|
+
err: err,
|
404
|
+
js_code: wrapper_js
|
408
405
|
# rubocop:enable Style/RaiseArgs
|
409
406
|
end
|
410
407
|
|
@@ -1,5 +1,44 @@
|
|
1
1
|
# Images
|
2
2
|
|
3
|
+
1. leading slash necessary on the
|
4
|
+
a. Option name for the file-loader and url-loader (todo reference)
|
5
|
+
b. Option publicPath for the output (todo reference)
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
```
|
12
|
+
const assetLoaderRules = [
|
13
|
+
{
|
14
|
+
test: /\.(jpe?g|png|gif|ico|woff)$/,
|
15
|
+
use: {
|
16
|
+
loader: 'url-loader',
|
17
|
+
options: {
|
18
|
+
limit: urlFileSizeCutover,
|
19
|
+
// Leading slash is 100% needed
|
20
|
+
name: 'images/[hash].[ext]',
|
21
|
+
},
|
22
|
+
},
|
23
|
+
},
|
24
|
+
{
|
25
|
+
test: /\.(ttf|eot|svg)$/,
|
26
|
+
use: {
|
27
|
+
loader: 'file-loader',
|
28
|
+
options: {
|
29
|
+
// Leading slash is 100% needed
|
30
|
+
name: '/images/[hash].[ext]',
|
31
|
+
}
|
32
|
+
},
|
33
|
+
},
|
34
|
+
];
|
35
|
+
|
36
|
+
```
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
3
42
|
A full example can be found at [spec/dummy/client/app/components/ImageExample/ImageExample.js](../../spec/dummy/client/app/components/ImageExample/ImageExample.js)
|
4
43
|
|
5
44
|
You are free to use images either in image tags or as background images in SCSS files. You can
|
@@ -9,27 +48,11 @@ is done with CSS modules.
|
|
9
48
|
**images** is a defined alias, so "images/foobar.jpg" would point to the file at
|
10
49
|
`/client/app/assets/images/foobar.jpg.`
|
11
50
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
as a background image or within an `img` tag.
|
20
|
-
|
21
|
-
The reason why this is done is that the sass-loader assumes that images will be relative to the
|
22
|
-
deployed sass file, which will already be `/assets/some-file.css`. Thus, the sass-loader is already
|
23
|
-
going to prepend `/assets` to all images. The file-loader needs an option to specify that the
|
24
|
-
public path is `/assets` and that will get prepended to any image path. Consequently, if we didn't
|
25
|
-
distinguish background images from images for `img` tags, then the background image tags will get
|
26
|
-
an image path like `/assets/assets/some-file.svg` because the sass-loader thinks the path should be
|
27
|
-
`/assets/some-file.svg` and that gets added to what the file-loader will be doing.
|
28
|
-
|
29
|
-
We solve this by requiring a naming convention of `bg-` or `bg_` in the image names. Be warned that
|
30
|
-
the regexp does not check that these three characters are the beginning of a name or path. They can
|
31
|
-
be anywhere in the string. Of course, you can create your convention.
|
32
|
-
|
33
|
-
You can see this configured: [spec/dummy/client/webpack.common.js](../../spec/dummy/client/webpack.common.js)
|
51
|
+
```
|
52
|
+
resolve: {
|
53
|
+
alias: {
|
54
|
+
images: join(process.cwd(), 'app', 'assets', 'images'),
|
55
|
+
},
|
56
|
+
},
|
57
|
+
```
|
34
58
|
|
35
|
-
_Note, all of this may change when we skip the asset pipeline for processing files in the near future._
|
@@ -17,15 +17,15 @@ The point is that you have separate files for top level client or server side, a
|
|
17
17
|
## Troubleshooting Server Rendering
|
18
18
|
|
19
19
|
1. First be sure your code works with server rendering disabled (`prerender: false`)
|
20
|
-
2. `export TRACE_REACT_ON_RAILS=
|
20
|
+
2. `export TRACE_REACT_ON_RAILS=TRUE` Turn this on to get both the invocation code for you component, as well as the whole file used to setup the JavaScript context.
|
21
21
|
|
22
22
|
## setTimeout and setInterval
|
23
23
|
|
24
|
-
These methods are polyfilled for server rendering to be no-ops. We don't log calls to these by default as some libraries, namely babel-polyfill, will call setTimout. If you wish to log calls to setTimeout and setInterval, set the ENV value: `export TRACE_REACT_ON_RAILS=
|
24
|
+
These methods are polyfilled for server rendering to be no-ops. We don't log calls to these by default as some libraries, namely babel-polyfill, will call setTimout. If you wish to log calls to setTimeout and setInterval, set the ENV value: `export TRACE_REACT_ON_RAILS=TRUE`.
|
25
25
|
|
26
26
|
Here's an example of this which shows the line numbers that end up calling setTimeout:
|
27
27
|
```
|
28
|
-
➜ ~/shakacode/react_on_rails/gen-examples/examples/basic-server-rendering (add-rails-helper-to-generator u=) ✗ export TRACE_REACT_ON_RAILS=
|
28
|
+
➜ ~/shakacode/react_on_rails/gen-examples/examples/basic-server-rendering (add-rails-helper-to-generator u=) ✗ export TRACE_REACT_ON_RAILS=TRUE
|
29
29
|
➜ ~/shakacode/react_on_rails/gen-examples/examples/basic-server-rendering (add-rails-helper-to-generator u=) ✗ rspec
|
30
30
|
Hello World
|
31
31
|
Building Webpack client-rendering assets...
|
data/docs/tutorial.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# React on Rails Basic Tutorial
|
2
2
|
|
3
|
-
This tutorial setups up a new Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering. It is updated to
|
3
|
+
This tutorial setups up a new Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering. It is updated to 8.0.0.
|
4
4
|
|
5
|
-
After finishing this tutorial you will get application that can do the following (live on Heroku):
|
5
|
+
After finishing this tutorial you will get an application that can do the following (live on Heroku):
|
6
6
|
|
7
7
|
![example](https://cloud.githubusercontent.com/assets/371302/17368567/111cc722-596b-11e6-9b72-ac5967a60e42.gif)
|
8
8
|
|
9
9
|
You can find here:
|
10
|
-
* [Source code for this app in PR, using the --redux option](https://github.com/shakacode/react_on_rails-test-new-redux-generation/pull/
|
11
|
-
* [Live on Heroku](https://react-on-rails-redux-
|
10
|
+
* [Source code for this app in PR, using the --redux option](https://github.com/shakacode/react_on_rails-test-new-redux-generation/pull/17) and [for Heroku](https://github.com/shakacode/react_on_rails-test-new-redux-generation/pull/18).
|
11
|
+
* [Live on Heroku](https://react-on-rails-redux-gen-8-0-0.herokuapp.com/)
|
12
12
|
|
13
13
|
By the time you read this, the latest may have changed. Be sure to check the versions here:
|
14
14
|
|
@@ -17,9 +17,9 @@ By the time you read this, the latest may have changed. Be sure to check the ver
|
|
17
17
|
|
18
18
|
_Note: some of the screen images below show the "npm" command. react_on_rails 6.6.0 and greater uses `yarn`._
|
19
19
|
|
20
|
-
##Setting up the environment
|
20
|
+
## Setting up the environment
|
21
21
|
|
22
|
-
Trying out **React on Rails** is super easy, so long as you have the basic prerequisites. This includes the basics for Rails 4.x and node version 6+. I recommend `rvm` and `nvm` to install Ruby and Node, and [brew](https://brew.sh/) to install [yarn](https://yarnpkg.com/en/docs/install#mac-tab). Rails can be installed as ordinary gem.
|
22
|
+
Trying out **React on Rails** is super easy, so long as you have the basic prerequisites. This includes the basics for Rails 4.x and node version 6+. I recommend `rvm` and `nvm` to install Ruby and Node, and [brew](https://brew.sh/) to install [yarn](https://yarnpkg.com/en/docs/install#mac-tab). Rails can be installed as an ordinary gem.
|
23
23
|
|
24
24
|
```
|
25
25
|
nvm install node # download and install latest stable Node
|
@@ -98,11 +98,12 @@ web: rails s -p 8080 -b 0.0.0.0
|
|
98
98
|
|
99
99
|
Then visit https://your-shared-addr.c9users.io:8080/hello_world
|
100
100
|
|
101
|
+
|
101
102
|
## RubyMine
|
102
103
|
|
103
104
|
It's super important to exclude certain directories from RubyMine or else it will slow to a crawl as it tries to parse all the npm files.
|
104
105
|
|
105
|
-
* `app/assets/webpack`
|
106
|
+
* `public/webpack` (or `app/assets/webpack` on older versions of react_on_rails)
|
106
107
|
* `client/node_modules`
|
107
108
|
|
108
109
|
## Deploying to Heroku
|
@@ -215,10 +216,10 @@ git push heroku master
|
|
215
216
|
![10](https://cloud.githubusercontent.com/assets/20628911/17465017/1f38fbaa-5cf4-11e6-8d86-a3d91e3878e0.png)
|
216
217
|
|
217
218
|
## Links
|
218
|
-
These are updated for
|
219
|
+
These are updated for 8.0.0:
|
219
220
|
|
220
|
-
* [PR for using the generator with the Redux option](https://github.com/shakacode/react_on_rails-test-new-redux-generation/pull/
|
221
|
-
* [PR showing the changes to deploy to Heroku](https://github.com/shakacode/react_on_rails-test-new-redux-generation/pull/
|
222
|
-
* [Live on Heroku](https://hello-react-on-rails.herokuapp.com/)
|
221
|
+
* [PR for using the generator with the Redux option](https://github.com/shakacode/react_on_rails-test-new-redux-generation/pull/17)
|
222
|
+
* [PR showing the changes to deploy to Heroku](https://github.com/shakacode/react_on_rails-test-new-redux-generation/pull/18)
|
223
|
+
* [Live on Heroku](https://hello-react-on-rails-8-0-0.herokuapp.com/)
|
223
224
|
|
224
225
|
Feedback is greatly appreciated! As are stars on github! If you want personalized help, don't hesitate to get in touch with us at [contact@shakacode.com](mailto:contact@shakacode.com).
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# rubocop:disable Metrics/ClassLength
|
2
|
+
|
1
3
|
require "rails/generators"
|
2
4
|
require_relative "generator_messages"
|
3
5
|
require_relative "generator_helper"
|
@@ -45,8 +47,7 @@ module ReactOnRails
|
|
45
47
|
def copy_base_files
|
46
48
|
base_path = "base/base/"
|
47
49
|
base_files = %w(app/controllers/hello_world_controller.rb
|
48
|
-
config/
|
49
|
-
config/webpack/development.server.yml
|
50
|
+
config/webpacker_lite.yml
|
50
51
|
client/.babelrc
|
51
52
|
client/webpack.config.js
|
52
53
|
client/REACT_ON_RAILS_CLIENT_README.md)
|
@@ -58,10 +59,17 @@ module ReactOnRails
|
|
58
59
|
%w(app/views/layouts/hello_world.html.erb
|
59
60
|
config/initializers/react_on_rails.rb
|
60
61
|
Procfile.dev
|
61
|
-
package.json
|
62
62
|
client/package.json).each { |file| template("#{base_path}#{file}.tt", file) }
|
63
63
|
end
|
64
64
|
|
65
|
+
def template_package_json
|
66
|
+
if dest_file_exists?("package.json")
|
67
|
+
add_yarn_postinstall_script_in_package_json
|
68
|
+
else
|
69
|
+
template("base/base/package.json", "package.json")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
65
73
|
def add_base_gems_to_gemfile
|
66
74
|
append_to_file("Gemfile", "\ngem 'mini_racer', platforms: :ruby\ngem 'webpacker_lite'\n")
|
67
75
|
end
|
@@ -140,6 +148,55 @@ Rails.application.config.assets.paths << Rails.root.join("public", "webpack", Ra
|
|
140
148
|
|
141
149
|
private
|
142
150
|
|
151
|
+
def add_yarn_postinstall_script_in_package_json
|
152
|
+
client_package_json = File.join(destination_root, "package.json")
|
153
|
+
contents = File.read(client_package_json)
|
154
|
+
postinstall = %("postinstall": "cd client && yarn install")
|
155
|
+
if contents =~ /"scripts" *:/
|
156
|
+
replacement = <<-STRING
|
157
|
+
"scripts": {
|
158
|
+
#{postinstall},
|
159
|
+
STRING
|
160
|
+
regexp = / {2}"scripts": {/
|
161
|
+
else
|
162
|
+
regexp = /^{/
|
163
|
+
replacement = <<-STRING
|
164
|
+
{
|
165
|
+
"scripts": {
|
166
|
+
#{postinstall}
|
167
|
+
},
|
168
|
+
STRING
|
169
|
+
end
|
170
|
+
|
171
|
+
contents.gsub!(regexp, replacement)
|
172
|
+
File.open(client_package_json, "w+") { |f| f.puts contents }
|
173
|
+
end
|
174
|
+
|
175
|
+
# From https://github.com/rails/rails/blob/4c940b2dbfb457f67c6250b720f63501d74a45fd/railties/lib/rails/generators/rails/app/app_generator.rb
|
176
|
+
def app_name
|
177
|
+
@app_name ||= (defined_app_const_base? ? defined_app_name : File.basename(destination_root))
|
178
|
+
.tr('\\', "").tr(". ", "_")
|
179
|
+
end
|
180
|
+
|
181
|
+
def defined_app_name
|
182
|
+
defined_app_const_base.underscore
|
183
|
+
end
|
184
|
+
|
185
|
+
def defined_app_const_base
|
186
|
+
Rails.respond_to?(:application) && defined?(Rails::Application) &&
|
187
|
+
Rails.application.is_a?(Rails::Application) && Rails.application.class.name.sub(/::Application$/, "")
|
188
|
+
end
|
189
|
+
|
190
|
+
alias defined_app_const_base? defined_app_const_base
|
191
|
+
|
192
|
+
def app_const_base
|
193
|
+
@app_const_base ||= defined_app_const_base || app_name.gsub(/\W/, "_").squeeze("_").camelize
|
194
|
+
end
|
195
|
+
|
196
|
+
def app_const
|
197
|
+
@app_const ||= "#{app_const_base}::Application"
|
198
|
+
end
|
199
|
+
|
143
200
|
def add_configure_rspec_to_compile_assets(helper_file)
|
144
201
|
search_str = "RSpec.configure do |config|"
|
145
202
|
gsub_file(helper_file, search_str, CONFIGURE_RSPEC_TO_COMPILE_ASSETS)
|
@@ -47,13 +47,11 @@ module ReactOnRails
|
|
47
47
|
|
48
48
|
def add_test_related_gems_to_gemfile
|
49
49
|
gem("rspec-rails", group: :test)
|
50
|
-
gem("capybara", group: :test)
|
51
|
-
gem("selenium-webdriver", group: :test)
|
52
50
|
gem("coveralls", require: false)
|
53
51
|
gem("poltergeist")
|
54
52
|
end
|
55
53
|
|
56
|
-
def
|
54
|
+
def replace_prerender_if_server_rendering
|
57
55
|
return unless options.example_server_rendering
|
58
56
|
hello_world_index = File.join(destination_root, "app", "views", "hello_world", "index.html.erb")
|
59
57
|
hello_world_contents = File.read(hello_world_index)
|
@@ -62,6 +60,19 @@ module ReactOnRails
|
|
62
60
|
|
63
61
|
File.open(hello_world_index, "w+") { |f| f.puts new_hello_world_contents }
|
64
62
|
end
|
63
|
+
|
64
|
+
def add_yarn_relative_install_script_in_client_package_json
|
65
|
+
client_package_json = File.join(destination_root, "client", "package.json")
|
66
|
+
contents = File.read(client_package_json)
|
67
|
+
replacement_value = <<-STRING
|
68
|
+
"scripts": {
|
69
|
+
"postinstall": "yarn run install-react-on-rails",
|
70
|
+
"install-react-on-rails": "rm -rf node_modules/react-on-rails && npm i 'file:../../../..'",
|
71
|
+
STRING
|
72
|
+
new_client_package_json_contents = contents.gsub(/ {2}"scripts": {/,
|
73
|
+
replacement_value)
|
74
|
+
File.open(client_package_json, "w+") { |f| f.puts new_client_package_json_contents }
|
75
|
+
end
|
65
76
|
end
|
66
77
|
end
|
67
78
|
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
web: rails s -p 3000
|
2
|
-
client: sh -c 'rm -rf public/webpack/* || true && cd client && bundle exec rake react_on_rails:locale && yarn run build:development'
|
2
|
+
client: sh -c 'rm -rf public/webpack/development/* || true && cd client && bundle exec rake react_on_rails:locale && yarn run build:development'
|
data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb.tt
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
<%%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
|
8
8
|
<%%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
|
9
|
-
<%%= javascript_pack_tag '
|
9
|
+
<%%= javascript_pack_tag 'webpack-bundle' %>
|
10
10
|
</head>
|
11
11
|
|
12
12
|
<body>
|
@@ -1,12 +1,7 @@
|
|
1
1
|
<%- require "react_on_rails/version_syntax_converter" -%>
|
2
2
|
{
|
3
|
-
"name": "
|
4
|
-
"version": "0.0.1",
|
3
|
+
"name": "<%= app_name %>",
|
5
4
|
"private": true,
|
6
|
-
"engines": {
|
7
|
-
"node": "6.9.0",
|
8
|
-
"npm": "4.1.1"
|
9
|
-
},
|
10
5
|
"scripts": {
|
11
6
|
"build:test": "NODE_ENV=test webpack --config webpack.config.js",
|
12
7
|
"build:production": "NODE_ENV=production webpack --config webpack.config.js",
|
@@ -1,41 +1,49 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
// For inspiration on your webpack configuration, see:
|
2
|
+
// https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client
|
3
|
+
// https://github.com/shakacode/react-webpack-rails-tutorial/tree/master/client
|
4
4
|
|
5
5
|
const webpack = require('webpack');
|
6
6
|
const { resolve } = require('path');
|
7
|
+
|
7
8
|
const ManifestPlugin = require('webpack-manifest-plugin');
|
8
9
|
const webpackConfigLoader = require('react-on-rails/webpackConfigLoader');
|
9
10
|
|
10
|
-
const configPath = resolve('..', 'config'
|
11
|
-
const {
|
12
|
-
|
13
|
-
const devBuild = env !== 'production';
|
11
|
+
const configPath = resolve('..', 'config');
|
12
|
+
const { devBuild, manifest, webpackOutputPath, webpackPublicOutputDir } =
|
13
|
+
webpackConfigLoader(configPath);
|
14
14
|
|
15
15
|
const config = {
|
16
16
|
|
17
17
|
context: resolve(__dirname),
|
18
18
|
|
19
|
-
entry:
|
20
|
-
'
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
entry: {
|
20
|
+
'webpack-bundle': [
|
21
|
+
'es5-shim/es5-shim',
|
22
|
+
'es5-shim/es5-sham',
|
23
|
+
'babel-polyfill',
|
24
|
+
'./app/bundles/HelloWorld/startup/registration',
|
25
|
+
],
|
26
|
+
},
|
25
27
|
|
26
28
|
output: {
|
27
|
-
|
28
|
-
|
29
|
+
// Name comes from the entry section.
|
30
|
+
filename: '[name]-[hash].js',
|
31
|
+
|
32
|
+
// Leading slash is necessary
|
33
|
+
publicPath: `/${webpackPublicOutputDir}`,
|
34
|
+
path: webpackOutputPath,
|
29
35
|
},
|
30
36
|
|
31
37
|
resolve: {
|
32
38
|
extensions: ['.js', '.jsx'],
|
33
39
|
},
|
34
40
|
|
35
|
-
|
36
41
|
plugins: [
|
37
|
-
new webpack.EnvironmentPlugin(
|
38
|
-
|
42
|
+
new webpack.EnvironmentPlugin({
|
43
|
+
NODE_ENV: 'development', // use 'development' unless process.env.NODE_ENV is defined
|
44
|
+
DEBUG: false,
|
45
|
+
}),
|
46
|
+
new ManifestPlugin({ fileName: manifest, writeToFileEmit: true }),
|
39
47
|
],
|
40
48
|
|
41
49
|
module: {
|
@@ -47,7 +55,7 @@ const config = {
|
|
47
55
|
options: {
|
48
56
|
shim: 'es5-shim/es5-shim',
|
49
57
|
sham: 'es5-shim/es5-sham',
|
50
|
-
}
|
58
|
+
},
|
51
59
|
},
|
52
60
|
},
|
53
61
|
{
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Note: Base output directory of /public is assumed for static files
|
2
|
+
default: &default
|
3
|
+
manifest: manifest.json
|
4
|
+
# Used in your webpack configuration. Must be created in the
|
5
|
+
# webpack_public_output_dir folder
|
6
|
+
|
7
|
+
development:
|
8
|
+
<<: *default
|
9
|
+
# generated files for development, in /public/webpack/development
|
10
|
+
webpack_public_output_dir: webpack/development
|
11
|
+
|
12
|
+
# Default is localhost:3500
|
13
|
+
hot_reloading_host: localhost:3500
|
14
|
+
|
15
|
+
# Developer note: considering removing this option so it can ONLY be turned by using an ENV value.
|
16
|
+
# Default is false, ENV 'HOT_RELOAD' will always override
|
17
|
+
hot_reloading_enabled_by_default: false
|
18
|
+
|
19
|
+
test:
|
20
|
+
<<: *default
|
21
|
+
# generated files for tests, in /public/webpack/test
|
22
|
+
webpack_public_output_dir: webpack/test
|
23
|
+
|
24
|
+
production:
|
25
|
+
<<: *default
|
26
|
+
# generated files for tests, in /public/webpack/production
|
27
|
+
webpack_public_output_dir: webpack/production
|
@@ -1,14 +1,8 @@
|
|
1
1
|
{
|
2
|
-
"name": "
|
3
|
-
"version": "0.0.1",
|
2
|
+
"name": "<%= app_name %>",
|
4
3
|
"private": true,
|
5
|
-
"
|
6
|
-
"node": "6.9.0",
|
7
|
-
"npm": "4.1.1"
|
8
|
-
},
|
4
|
+
"dependencies": {},
|
9
5
|
"scripts": {
|
10
|
-
"postinstall": "cd client && yarn install"
|
11
|
-
"rails-server": "echo 'visit http://localhost:3000/hello_world' && foreman start -f Procfile.dev",
|
12
|
-
"test": "rspec"
|
6
|
+
"postinstall": "cd client && yarn install"
|
13
7
|
}
|
14
8
|
}
|
@@ -12,7 +12,7 @@ module ReactOnRails
|
|
12
12
|
|
13
13
|
def self.reset_pool_if_server_bundle_was_modified
|
14
14
|
return unless ReactOnRails.configuration.development_mode
|
15
|
-
file_mtime = File.mtime(ReactOnRails::Utils.
|
15
|
+
file_mtime = File.mtime(ReactOnRails::Utils.server_bundle_js_file_path)
|
16
16
|
@server_bundle_timestamp ||= file_mtime
|
17
17
|
return if @server_bundle_timestamp == file_mtime
|
18
18
|
ReactOnRails::ServerRenderingPool.reset_pool
|
@@ -77,37 +77,36 @@ module ReactOnRails
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def create_js_context
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
return if ReactOnRails.configuration.server_bundle_js_file.blank?
|
81
|
+
|
82
|
+
server_js_file = ReactOnRails::Utils.server_bundle_js_file_path
|
83
|
+
|
84
|
+
unless File.exist?(server_js_file)
|
85
|
+
msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be "\
|
86
|
+
"read. You may set the server_bundle_js_file in your configuration to be \"\" to "\
|
87
|
+
"avoid this warning"
|
88
|
+
raise msg
|
89
|
+
end
|
90
|
+
|
91
|
+
bundle_js_code = File.read(server_js_file)
|
92
|
+
base_js_code = <<-JS
|
84
93
|
#{console_polyfill}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
+
#{execjs_timer_polyfills}
|
95
|
+
#{bundle_js_code};
|
96
|
+
JS
|
97
|
+
file_name = "tmp/base_js_code.js"
|
98
|
+
begin
|
99
|
+
trace_messsage(base_js_code, file_name)
|
100
|
+
ExecJS.compile(base_js_code)
|
101
|
+
rescue => e
|
102
|
+
msg = "ERROR when compiling base_js_code! "\
|
94
103
|
"See file #{file_name} to "\
|
95
104
|
"correlate line numbers of error. Error is\n\n#{e.message}"\
|
96
105
|
"\n\n#{e.backtrace.join("\n")}"
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
102
|
-
else
|
103
|
-
if server_js_file.present?
|
104
|
-
msg = "You specified server rendering JS file: #{server_js_file}, but it cannot be "\
|
105
|
-
"read. You may set the server_bundle_js_file in your configuration to be \"\" to "\
|
106
|
-
"avoid this warning"
|
107
|
-
Rails.logger.warn msg
|
108
|
-
puts msg
|
109
|
-
end
|
110
|
-
ExecJS.compile("")
|
106
|
+
puts msg
|
107
|
+
Rails.logger.error(msg)
|
108
|
+
trace_messsage(base_js_code, file_name, true)
|
109
|
+
raise e
|
111
110
|
end
|
112
111
|
end
|
113
112
|
|
@@ -31,7 +31,7 @@ module ReactOnRails
|
|
31
31
|
# metatags - metatags to add the ensure_assets_compiled check.
|
32
32
|
# Default is :js, :server_rendering
|
33
33
|
def self.configure_rspec_to_compile_assets(config, *metatags)
|
34
|
-
metatags =
|
34
|
+
metatags = %i(js server_rendering controller) if metatags.empty?
|
35
35
|
|
36
36
|
metatags.each do |metatag|
|
37
37
|
config.before(:example, metatag) { ReactOnRails::TestHelper.ensure_assets_compiled }
|
@@ -55,7 +55,6 @@ module ReactOnRails
|
|
55
55
|
client_dir: nil,
|
56
56
|
generated_assets_dir: nil,
|
57
57
|
webpack_generated_files: nil)
|
58
|
-
|
59
58
|
if webpack_assets_status_checker.nil?
|
60
59
|
client_dir ||= Rails.root.join("client")
|
61
60
|
generated_assets_dir ||= ReactOnRails.configuration.generated_assets_dir
|
@@ -43,8 +43,8 @@ module ReactOnRails
|
|
43
43
|
def puts_start_compile_check_message(stale_files)
|
44
44
|
puts <<-MSG
|
45
45
|
|
46
|
-
Detected
|
47
|
-
#{stale_files.join("\n")}
|
46
|
+
Detected the following stale generated files:
|
47
|
+
#{stale_files.join("\n ")}
|
48
48
|
|
49
49
|
React on Rails will ensure your JavaScript generated files are up to date, using your
|
50
50
|
/client level package.json `#{ReactOnRails.configuration.npm_build_test_command}` command.
|
@@ -22,6 +22,11 @@ module ReactOnRails
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def stale_generated_webpack_files
|
25
|
+
manifest_needed = ReactOnRails::Utils.using_webpacker_lite? &&
|
26
|
+
!WebpackerLite::Manifest.exist?
|
27
|
+
|
28
|
+
return ["manifest.json"] if manifest_needed
|
29
|
+
|
25
30
|
most_recent_mtime = find_most_recent_mtime
|
26
31
|
all_compiled_assets.each_with_object([]) do |webpack_generated_file, stale_gen_list|
|
27
32
|
if !File.exist?(webpack_generated_file) ||
|
@@ -43,8 +48,8 @@ module ReactOnRails
|
|
43
48
|
|
44
49
|
def all_compiled_assets
|
45
50
|
@all_compiled_assets ||= begin
|
46
|
-
webpack_generated_files = @webpack_generated_files.map do |
|
47
|
-
|
51
|
+
webpack_generated_files = @webpack_generated_files.map do |bundle_name|
|
52
|
+
ReactOnRails::Utils.bundle_js_file_path(bundle_name)
|
48
53
|
end
|
49
54
|
if webpack_generated_files.present?
|
50
55
|
webpack_generated_files
|
data/lib/react_on_rails/utils.rb
CHANGED
@@ -15,9 +15,26 @@ module ReactOnRails
|
|
15
15
|
$CHILD_STATUS.exitstatus == 0
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.
|
19
|
-
|
20
|
-
|
18
|
+
def self.server_bundle_js_file_path
|
19
|
+
bundle_js_file_path(ReactOnRails.configuration.server_bundle_js_file)
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO: conturbo Write Test for this, with BOTH webpacker_lite installed and not, and
|
23
|
+
# with case for webpacker_lite, but server file is not in the file
|
24
|
+
def self.bundle_js_file_path(bundle_name)
|
25
|
+
# For testing outside of Rails app
|
26
|
+
|
27
|
+
if using_webpacker_lite? && WebpackerLite::Manifest.lookup(bundle_name)
|
28
|
+
# If using webpacker_lite gem
|
29
|
+
public_subdir_hashed_file_name = ActionController::Base.helpers.asset_pack_path(bundle_name)
|
30
|
+
return File.join("public", public_subdir_hashed_file_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
File.join(ReactOnRails.configuration.generated_assets_dir, bundle_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.using_webpacker_lite?
|
37
|
+
ActionController::Base.helpers.respond_to?(:asset_pack_path)
|
21
38
|
end
|
22
39
|
|
23
40
|
def self.running_on_windows?
|
data/package.json
CHANGED
data/rakelib/dummy_apps.rake
CHANGED
data/rakelib/examples.rake
CHANGED
@@ -11,7 +11,7 @@ include ReactOnRails::TaskHelpers
|
|
11
11
|
namespace :examples do
|
12
12
|
# Loads data from examples_config.yml and instantiates corresponding ExampleType objects
|
13
13
|
examples_config_file = File.expand_path("../examples_config.yml", __FILE__)
|
14
|
-
examples_config = symbolize_keys(YAML.
|
14
|
+
examples_config = symbolize_keys(YAML.safe_load(File.read(examples_config_file)))
|
15
15
|
examples_config[:example_type_data].each { |example_type_data| ExampleType.new(symbolize_keys(example_type_data)) }
|
16
16
|
|
17
17
|
# Define tasks for each example type
|
data/rakelib/lint.rake
CHANGED
data/rakelib/release.rake
CHANGED
@@ -20,10 +20,10 @@ which are installed via `bundle install` and `yarn`
|
|
20
20
|
|
21
21
|
Example: `rake release[2.1.0,false]`")
|
22
22
|
|
23
|
-
task :release, [
|
23
|
+
task :release, %i[gem_version dry_run tools_install] do |_t, args|
|
24
24
|
class MessageHandler
|
25
25
|
def add_error(error)
|
26
|
-
|
26
|
+
raise error
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
data/rakelib/run_rspec.rake
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
if ENV["USE_COVERALLS"] == "TRUE"
|
2
|
-
require "coveralls/rake/task"
|
3
|
-
end
|
1
|
+
require "coveralls/rake/task" if ENV["USE_COVERALLS"] == "TRUE"
|
4
2
|
|
5
3
|
require "pathname"
|
6
4
|
|
@@ -57,17 +55,15 @@ namespace :run_rspec do
|
|
57
55
|
sh %(COVERAGE=true rspec spec/empty_spec.rb)
|
58
56
|
end
|
59
57
|
|
60
|
-
if ENV["USE_COVERALLS"] == "TRUE"
|
61
|
-
Coveralls::RakeTask.new
|
62
|
-
end
|
58
|
+
Coveralls::RakeTask.new if ENV["USE_COVERALLS"] == "TRUE"
|
63
59
|
|
64
60
|
desc "run all tests no examples"
|
65
|
-
task all_but_examples: [
|
61
|
+
task all_but_examples: %i[gem dummy_no_turbolinks dummy_turbolinks_2 dummy empty js_tests] do
|
66
62
|
puts "Completed all RSpec tests"
|
67
63
|
end
|
68
64
|
|
69
65
|
desc "run all tests"
|
70
|
-
task run_rspec: [
|
66
|
+
task run_rspec: %i[all_but_examples examples] do
|
71
67
|
puts "Completed all RSpec tests"
|
72
68
|
end
|
73
69
|
end
|
@@ -85,16 +81,17 @@ desc msg
|
|
85
81
|
task run_rspec: ["run_rspec:run_rspec"]
|
86
82
|
|
87
83
|
private
|
84
|
+
|
88
85
|
def calc_path(dir)
|
89
|
-
if dir.is_a?(String)
|
90
|
-
|
86
|
+
path = if dir.is_a?(String)
|
87
|
+
if dir.start_with?(File::SEPARATOR)
|
91
88
|
Pathname.new(dir)
|
92
89
|
else
|
93
90
|
Pathname.new(File.join(gem_root, dir))
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
91
|
+
end
|
92
|
+
else
|
93
|
+
dir
|
94
|
+
end
|
98
95
|
path
|
99
96
|
end
|
100
97
|
|
data/react_on_rails.gemspec
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
5
|
+
require "react_on_rails/version"
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "react_on_rails"
|
@@ -9,8 +10,8 @@ Gem::Specification.new do |s|
|
|
9
10
|
s.authors = ["Justin Gordon"]
|
10
11
|
s.email = ["justin@shakacode.com"]
|
11
12
|
|
12
|
-
s.summary =
|
13
|
-
s.description =
|
13
|
+
s.summary = "Rails with react server rendering with webpack. "
|
14
|
+
s.description = "See README.md"
|
14
15
|
s.homepage = "https://github.com/shakacode/react_on_rails"
|
15
16
|
s.license = "MIT"
|
16
17
|
|
@@ -19,7 +20,7 @@ Gem::Specification.new do |s|
|
|
19
20
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
21
|
s.require_paths = ["lib"]
|
21
22
|
|
22
|
-
s.required_ruby_version =
|
23
|
+
s.required_ruby_version = ">= 2.0.0"
|
23
24
|
|
24
25
|
s.add_dependency "connection_pool"
|
25
26
|
s.add_dependency "execjs", "~> 2.5"
|
data/webpackConfigLoader.js
CHANGED
@@ -1,27 +1,96 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
/**
|
2
|
+
* Allow defaults for the config/webpacker_lite.yml. Thee values in this file MUST match values
|
3
|
+
* in README for https://github.com/shakacode/webpacker_lite
|
4
|
+
*
|
5
|
+
* webpack_public_output_dir: 'webpack'
|
6
|
+
* manifest: 'manifest.json'
|
7
|
+
*
|
8
|
+
* hot_reloading_enabled_by_default: false
|
9
|
+
* hot_reloading_host: localhost:3500
|
10
|
+
*
|
11
|
+
* NOTE: for hot reloading, env.HOT_RELOADING value will override any config value. This env value
|
12
|
+
* should be set to TRUE to turn this on.
|
13
|
+
*/
|
14
|
+
const { join, resolve } = require('path');
|
3
15
|
const { safeLoad } = require('js-yaml');
|
4
16
|
const { readFileSync } = require('fs');
|
5
17
|
|
18
|
+
const DEFAULT_WEBPACK_PUBLIC_OUTPUT_DIR = 'webpack';
|
19
|
+
const DEFAULT_MANIFEST = 'manifest.json';
|
20
|
+
const DEFAULT_HOT_RELOADING_HOST = 'localhost:3500';
|
21
|
+
const HOT_RELOADING_ENABLED_BY_DEFAULT = false;
|
22
|
+
|
23
|
+
function getLocation(href) {
|
24
|
+
const match = href.match(/^(https?:)\/\/(([^:/?#]*)(?::([0-9]+))?)([/]?[^?#]*)(\?[^#]*|)(#.*|)$/);
|
25
|
+
|
26
|
+
return match && {
|
27
|
+
href,
|
28
|
+
protocol: match[1],
|
29
|
+
host: match[2],
|
30
|
+
hostname: match[3],
|
31
|
+
port: match[4],
|
32
|
+
pathname: match[5],
|
33
|
+
search: match[6],
|
34
|
+
hash: match[7],
|
35
|
+
};
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @param configPath, location where webpacker_lite.yml will be found
|
40
|
+
* @returns {{
|
41
|
+
* devBuild,
|
42
|
+
* hotReloadingEnabled,
|
43
|
+
* hotReloadingHost,
|
44
|
+
* hotReloadingPort,
|
45
|
+
* hotReloadingUrl,
|
46
|
+
* manifest,
|
47
|
+
* webpackOutputPath,
|
48
|
+
* webpackPublicOutputDir
|
49
|
+
* }}
|
50
|
+
*/
|
6
51
|
const configLoader = (configPath) => {
|
7
|
-
const
|
52
|
+
const env = process.env;
|
8
53
|
|
9
|
-
|
10
|
-
const
|
54
|
+
// Some test environments might not have the NODE_ENV set, so we'll have fallbacks.
|
55
|
+
const configEnv = (process.env.NODE_ENV || process.env.RAILS_ENV || 'development');
|
56
|
+
const ymlConfigPath = join(configPath, 'webpacker_lite.yml');
|
57
|
+
const configuration = safeLoad(readFileSync(ymlConfigPath, 'utf8'))[configEnv];
|
11
58
|
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
const productionBuild = env.NODE_ENV === 'production';
|
59
|
+
const devBuild = env !== 'production';
|
60
|
+
const hotReloadingHost = configuration.hot_reloading_host || DEFAULT_HOT_RELOADING_HOST;
|
16
61
|
|
17
|
-
|
18
|
-
|
62
|
+
// NOTE: Rails path is hard coded to `/public`
|
63
|
+
const webpackPublicOutputDir = configuration.webpack_public_output_dir ||
|
64
|
+
DEFAULT_WEBPACK_PUBLIC_OUTPUT_DIR;
|
65
|
+
const webpackOutputPath = resolve(configPath, '..', 'public', webpackPublicOutputDir);
|
66
|
+
|
67
|
+
const manifest = configuration.manifest || DEFAULT_MANIFEST;
|
68
|
+
|
69
|
+
const hotReloadingEnabled = (env.HOT_RELOADING === 'TRUE' || env.HOT_RELOADING === 'YES' ||
|
70
|
+
configuration.hot_reloading_enabled_by_default || HOT_RELOADING_ENABLED_BY_DEFAULT);
|
71
|
+
|
72
|
+
const hotReloadingUrl = hotReloadingHost.match(/^http/)
|
73
|
+
? hotReloadingHost
|
74
|
+
: `http://${hotReloadingHost}`;
|
75
|
+
|
76
|
+
const url = getLocation(hotReloadingUrl);
|
77
|
+
const hotReloadingPort = url.port;
|
78
|
+
const hotReloadingHostname = url.hostname;
|
79
|
+
if (hotReloadingPort === '' || hotReloadingHostname === '') {
|
80
|
+
const msg = 'Missing port number. Please specify the `hot_reloading_host` like `localhost:3500`';
|
81
|
+
throw new Error(msg);
|
82
|
+
}
|
19
83
|
|
20
84
|
return {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
85
|
+
devBuild,
|
86
|
+
hotReloadingEnabled,
|
87
|
+
hotReloadingHost,
|
88
|
+
hotReloadingHostname,
|
89
|
+
hotReloadingPort,
|
90
|
+
hotReloadingUrl,
|
91
|
+
manifest,
|
92
|
+
webpackOutputPath,
|
93
|
+
webpackPublicOutputDir,
|
25
94
|
};
|
26
95
|
};
|
27
96
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: react_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.0.0.beta.
|
4
|
+
version: 8.0.0.beta.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|
@@ -382,8 +382,7 @@ files:
|
|
382
382
|
- lib/generators/react_on_rails/templates/base/base/client/package.json.tt
|
383
383
|
- lib/generators/react_on_rails/templates/base/base/client/webpack.config.js
|
384
384
|
- lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt
|
385
|
-
- lib/generators/react_on_rails/templates/base/base/config/
|
386
|
-
- lib/generators/react_on_rails/templates/base/base/config/webpack/paths.yml
|
385
|
+
- lib/generators/react_on_rails/templates/base/base/config/webpacker_lite.yml
|
387
386
|
- lib/generators/react_on_rails/templates/base/base/package.json.tt
|
388
387
|
- lib/generators/react_on_rails/templates/dev_tests/.rspec
|
389
388
|
- lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Used by webpacker_lite to configure the helpers and by webpack from the
|
2
|
-
# client/webpack.config.js file, in variable `paths`.
|
3
|
-
default: &default
|
4
|
-
output: public
|
5
|
-
manifest: manifest.json
|
6
|
-
|
7
|
-
development:
|
8
|
-
<<: *default
|
9
|
-
assets: webpack/development
|
10
|
-
|
11
|
-
test:
|
12
|
-
<<: *default
|
13
|
-
assets: webpack/test
|
14
|
-
|
15
|
-
production:
|
16
|
-
<<: *default
|
17
|
-
assets: webpack/production
|