react_on_rails 12.4.0.rc.0 → 12.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +2 -1
- data/.github/workflows/main.yml +3 -3
- data/CHANGELOG.md +27 -3
- data/Gemfile.development_dependencies +7 -6
- data/REACT-ON-RAILS-PRO-LICENSE +1 -1
- data/README.md +19 -10
- data/SUMMARY.md +9 -0
- data/docs/deployment/heroku-deployment.md +16 -5
- data/docs/guides/configuration.md +7 -8
- data/docs/guides/how-react-on-rails-works.md +0 -1
- data/docs/guides/tutorial.md +18 -14
- data/lib/generators/react_on_rails/base_generator.rb +46 -3
- data/lib/generators/react_on_rails/generator_helper.rb +4 -0
- data/lib/generators/react_on_rails/templates/.eslintrc +3 -1
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +4 -8
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +9 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +2 -1
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +4 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorldServer.js +5 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js +8 -0
- data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +1 -0
- data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +15 -0
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +1 -1
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt +17 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +15 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +27 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt +11 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +117 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpackConfig.js.tt +36 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpacker.yml +62 -0
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +2 -1
- data/lib/react_on_rails/configuration.rb +66 -33
- data/lib/react_on_rails/server_rendering_js_code.rb +13 -0
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +3 -1
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/tasks/assets.rake +5 -47
- data/lib/tasks/locale.rake +1 -2
- data/package.json +1 -1
- data/rakelib/example_type.rb +5 -1
- data/rakelib/examples.rake +7 -2
- data/rakelib/release.rake +3 -1
- data/rakelib/task_helpers.rb +7 -0
- data/react_on_rails.gemspec +3 -3
- metadata +22 -11
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42095c4558f10348cc26cb16a990b85bc2a5b7ccdc21d297fa1c461ce3b87ad5
|
4
|
+
data.tar.gz: 3592b3bf2a9d21746ea977f3be2c17478b7c440f4905dde5c5d7102e911715ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f32f47937ffe6af27f69b6f6b95a0ced2cb7b6c268f1c0e7ea04bd55c42c421cf1cae37ff479702bd47de8435bb802ce273e0aff9d533456dfe7a46d4abe9847
|
7
|
+
data.tar.gz: 338aef5f7c66e7d167afb518e9c28056b8425b29e9c98d783701ad492b6766b80cc25aaa993dec655941ee855883c15ef32321e6694984a8f2833a3a6629e560
|
data/.circleci/config.yml
CHANGED
@@ -55,7 +55,7 @@ aliases:
|
|
55
55
|
command: |
|
56
56
|
gem install bundler
|
57
57
|
echo "Bundler version: "; bundle --version
|
58
|
-
cd spec/dummy && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
58
|
+
cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
59
59
|
|
60
60
|
# Install ruby gems unless existing set of gems is satisfying bundler.
|
61
61
|
- &install-package-ruby-gems
|
@@ -63,6 +63,7 @@ aliases:
|
|
63
63
|
command: |
|
64
64
|
gem install bundler
|
65
65
|
echo "Bundler version: "; bundle --version
|
66
|
+
bundle lock --add-platform 'x86_64-linux'
|
66
67
|
bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
67
68
|
|
68
69
|
# Restore node_modules dir from cache using yarn.lock checksum as a key.
|
data/.github/workflows/main.yml
CHANGED
@@ -55,7 +55,7 @@ jobs:
|
|
55
55
|
path: spec/dummy/vendor/bundle
|
56
56
|
key: v4-dummy-app-gem-cache-${{ hashFiles('spec/dummy/Gemfile.lock') }}
|
57
57
|
- name: Install Ruby Gems for dummy app
|
58
|
-
run: cd spec/dummy && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
58
|
+
run: cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
59
59
|
- name: Build test bundles for dummy app
|
60
60
|
run: cd spec/dummy && yarn run build:test
|
61
61
|
- id: get-sha
|
@@ -131,9 +131,9 @@ jobs:
|
|
131
131
|
- name: yalc add react-on-rails
|
132
132
|
run: cd spec/dummy && yalc add react-on-rails
|
133
133
|
- name: Install Ruby Gems for package
|
134
|
-
run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
134
|
+
run: bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
135
135
|
- name: Install Ruby Gems for dummy app
|
136
|
-
run: cd spec/dummy && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
136
|
+
run: cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
137
137
|
- name: Ensure minimum required Chrome version
|
138
138
|
run: |
|
139
139
|
echo -e "Already installed $(google-chrome --version)\n"
|
data/CHANGELOG.md
CHANGED
@@ -16,8 +16,29 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
|
|
16
16
|
Changes since last non-beta release.
|
17
17
|
|
18
18
|
*Please add entries here for your pull requests that are not yet released.*
|
19
|
+
### [12.5.2] - 2021-12-29
|
20
|
+
### Fixed
|
21
|
+
- Usage of config.build_production_command for custom command for production builds fixed. [PR 1415](https://github.com/shakacode/react_on_rails/pull/1415) by [judahmeek](https://github.com/judahmeek).
|
22
|
+
|
23
|
+
### [12.5.1] - 2021-12-27
|
24
|
+
|
25
|
+
### Fixed
|
26
|
+
- A fatal server rendering error if running an ReactOnRails >=12.4.0 with ReactOnRails Pro <2.4.0. [PR 1412](https://github.com/shakacode/react_on_rails/pull/1412) by [judahmeek](https://github.com/judahmeek).
|
27
|
+
|
28
|
+
### [12.5.0] - 2021-12-26
|
19
29
|
|
20
30
|
#### Added
|
31
|
+
- Support for React 18, including the changed SSR API. [PR 1409](https://github.com/shakacode/react_on_rails/pull/1409) by [kylemellander](https://github.com/kylemellander).
|
32
|
+
- Added webpack configuration files as part of the generator and updated webpacker to version 6. [PR 1404](https://github.com/shakacode/react_on_rails/pull/1404) by [gscarv13](https://github.com/gscarv13).
|
33
|
+
- Supports Rails 7.
|
34
|
+
|
35
|
+
#### Changed
|
36
|
+
- Changed logic of determining the usage of the default rails/webpacker webpack config or a custom command to only check if the config.build_production_command is defined. [PR 1402](https://github.com/shakacode/react_on_rails/pull/1402)by [justin808](https://github.com/justin808) and [gscarv13](https://github.com/gscarv13).
|
37
|
+
- Minimimum required Ruby is 2.7 to match lastest rails/webpacker.
|
38
|
+
|
39
|
+
### [12.4.0] - 2021-09-22
|
40
|
+
#### Added
|
41
|
+
- ScoutAPM tracing support for server rendering [PR 1379](https://github.com/shakacode/react_on_rails/pull/1379) by [justin808](https://github.com/justin808).
|
21
42
|
|
22
43
|
- Ability to stop React on Rails from modifying or creating the `assets:precompile` task. [PR 1371](https://github.com/shakacode/react_on_rails/pull/1371) by [justin808](https://github.com/justin808). Thanks to [elstgav](https://github.com/elstgav) for [the suggestion](https://github.com/shakacode/react_on_rails/issues/1368)!
|
23
44
|
|
@@ -25,7 +46,6 @@ Changes since last non-beta release.
|
|
25
46
|
|
26
47
|
### [12.3.0] - 2021-07-26
|
27
48
|
#### Added
|
28
|
-
|
29
49
|
- Ability to use with Turbo (@hotwired/turbo), as Turbolinks gets obsolete. [PR 1374](https://github.com/shakacode/react_on_rails/pull/1374) by [pgruener](https://github.com/pgruener) and [PR 1377](https://github.com/shakacode/react_on_rails/pull/1377) by [mdesantis](https://github.com/mdesantis).
|
30
50
|
|
31
51
|
To configure turbo the following option can be set:
|
@@ -81,7 +101,7 @@ invoked to return the React component. In that case, you won't need to pass any
|
|
81
101
|
[PR 1268](https://github.com/shakacode/react_on_rails/pull/1268) by [justin808](https://github.com/justin808)
|
82
102
|
|
83
103
|
See [docs/guides/upgrading-react-on-rails](https://www.shakacode.com/react-on-rails/docs/guides/upgrading-react-on-rails#upgrading-to-v12)
|
84
|
-
for details.
|
104
|
+
for details.
|
85
105
|
|
86
106
|
#### Other Updates
|
87
107
|
* `react_on_rails` fully supports `rails/webpacker`. The example test app in `spec/dummy` was recently converted over to use rails/webpacker v4+. It's a good example of how to leverage rails/webpacker's webpack configuration for server-side rendering.
|
@@ -973,7 +993,11 @@ Best done with Object destructing:
|
|
973
993
|
##### Fixed
|
974
994
|
- Fix several generator related issues.
|
975
995
|
|
976
|
-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.
|
996
|
+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.5.2...master
|
997
|
+
[12.5.2]: https://github.com/shakacode/react_on_rails/compare/12.5.1...12.5.2
|
998
|
+
[12.5.1]: https://github.com/shakacode/react_on_rails/compare/12.5.0...12.5.1
|
999
|
+
[12.5.0]: https://github.com/shakacode/react_on_rails/compare/12.4.0...12.5.0
|
1000
|
+
[12.4.0]: https://github.com/shakacode/react_on_rails/compare/12.3.0...12.4.0
|
977
1001
|
[12.3.0]: https://github.com/shakacode/react_on_rails/compare/12.2.0...12.3.0
|
978
1002
|
[12.2.0]: https://github.com/shakacode/react_on_rails/compare/12.1.0...12.2.0
|
979
1003
|
[12.1.0]: https://github.com/shakacode/react_on_rails/compare/12.0.4...12.1.0
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
gem "webpacker"
|
3
|
+
gem "webpacker", "6.0.0.rc.6"
|
4
4
|
gem "bootsnap", require: false
|
5
|
-
gem "rails"
|
5
|
+
gem "rails", "~> 7.0"
|
6
6
|
gem "sqlite3"
|
7
|
-
gem "sass-rails"
|
7
|
+
gem "sass-rails", "~> 6.0"
|
8
8
|
gem "uglifier"
|
9
9
|
gem "jquery-rails"
|
10
10
|
gem "puma"
|
@@ -17,10 +17,11 @@ gem "jbuilder"
|
|
17
17
|
# bundle exec rake doc:rails generates the API under doc/api.
|
18
18
|
gem "sdoc", group: :doc
|
19
19
|
|
20
|
-
gem "sprockets"
|
20
|
+
gem "sprockets", "~> 4.0"
|
21
21
|
|
22
22
|
gem "amazing_print"
|
23
|
-
|
23
|
+
|
24
|
+
gem "mini_racer", "~> 0.5"
|
24
25
|
|
25
26
|
group :development, :test do
|
26
27
|
gem "listen"
|
@@ -33,7 +34,7 @@ group :development, :test do
|
|
33
34
|
gem "rubocop-performance", require: false
|
34
35
|
gem "rubocop-rspec", require: false
|
35
36
|
gem "scss_lint", require: false
|
36
|
-
gem "spring"
|
37
|
+
gem "spring", "~> 4.0"
|
37
38
|
end
|
38
39
|
|
39
40
|
group :test do
|
data/REACT-ON-RAILS-PRO-LICENSE
CHANGED
@@ -82,7 +82,7 @@ In no event will ShakaCode's liability exceed the Software license price as indi
|
|
82
82
|
|
83
83
|
13.5 Indemnification. You agree to defend, indemnify, and hold harmless ShakaCode from and against any lawsuits, claims, losses, damages, fines and expenses (including attorneys' fees and costs) arising out of your use of the Software or breach of this Agreement.
|
84
84
|
|
85
|
-
13.6 Governing Law. This Agreement is governed by the laws of the State of
|
85
|
+
13.6 Governing Law. This Agreement is governed by the laws of the State of Hawaii and the United States without regard to conflicts of laws provisions thereof, and without regard to the United Nations Convention on the International Sale of Goods or the Uniform Computer Information Transactions Act, as currently enacted by any jurisdiction or as may be codified or amended from time to time by any jurisdiction. The jurisdiction and venue for actions related to the subject matter hereof shall be the state of Hawaii and United States federal courts located in Kahului, Hawaii, and both parties hereby submit to the personal jurisdiction of such courts.
|
86
86
|
|
87
87
|
13.7 Attorneys’ Fees and Costs. The prevailing party in any action to enforce this Agreement will be entitled to recover its attorneys’ fees and costs in connection with such action.
|
88
88
|
|
data/README.md
CHANGED
@@ -11,6 +11,14 @@
|
|
11
11
|
|
12
12
|
[![License](https://img.shields.io/badge/license-mit-green.svg)](LICENSE.md) [![Build Status](https://travis-ci.org/shakacode/react_on_rails.svg?branch=master)](https://travis-ci.org/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) [![](https://ruby-gem-downloads-badge.herokuapp.com/react_on_rails?type=total)](https://rubygems.org/gems/react_on_rails)
|
13
13
|
|
14
|
+
# News
|
15
|
+
* Project is updated to support Rails 7!
|
16
|
+
* **React and Webpack with Ruby on Rails**: The current version of https://github.com/rails/webpacker will soon ship. While it won't be the default for Rails 7, it is not "deprecated." The core webpack configuration has become slimmer, allowing easier extension. If you want to get started today, use the master branch of [shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh) with `gem "webpacker", "6.0.0.rc.6"` Any updates to get to v6 from this point forward should be simple.
|
17
|
+
|
18
|
+
If you have time, please comment on Justin's final proposals for Webpacker v6: [webpacker/pulls/justin808](https://github.com/rails/webpacker/pulls/justin808).
|
19
|
+
|
20
|
+
-----
|
21
|
+
|
14
22
|
*These are the docs for React on Rails 12. To see the version 11 docs, [click here](https://github.com/shakacode/react_on_rails/tree/11.3.0).*
|
15
23
|
|
16
24
|
#### About
|
@@ -18,20 +26,20 @@ React on Rails integrates Rails with (server rendering of) Facebook's [React](ht
|
|
18
26
|
|
19
27
|
This project is maintained by the software consulting firm [ShakaCode](https://www.shakacode.com). We focus on Ruby on Rails applications with React front-ends, often using TypeScript or ReScript (ReasonML). We also build React Native apps and Gatsby sites. See [our recent work](https://www.shakacode.com/recent-work) for examples of what we do. ShakaCode.com (HiChee.com) is [hiring developers that like working on open-source](https://www.shakacode.com/career/).
|
20
28
|
|
21
|
-
|
29
|
+
Are you interested in optimizing your webpack setup for React on Rails including code
|
22
30
|
splitting with [react-router](https://github.com/ReactTraining/react-router#readme) and
|
23
|
-
|
31
|
+
[loadable-components](https://loadable-components.com/) with server-side rendering for SEO and hot-reloading for developers?
|
24
32
|
We did this for Popmenu, [lowering Heroku costs 20-25% while getting a 73% decrease in average response times](https://www.shakacode.com/recent-work/popmenu/). Check out [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/).
|
25
33
|
|
26
|
-
|
34
|
+
For more information, feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com), maintainer of React on Rails.
|
27
35
|
|
28
36
|
# Documentation
|
29
37
|
|
30
|
-
See the documentation at [shakacode.com/react-on-rails/docs](https://www.shakacode.com/react-on-rails/docs/)
|
38
|
+
See the documentation at **[shakacode.com/react-on-rails/docs](https://www.shakacode.com/react-on-rails/docs/)**.
|
31
39
|
|
32
40
|
## Project Objective
|
33
41
|
|
34
|
-
To provide a high performance framework for integrating Ruby on Rails with React via the [**Webpacker**](https://github.com/rails/webpacker) gem especially
|
42
|
+
To provide a high performance framework for integrating Ruby on Rails with React via the [**Webpacker**](https://github.com/rails/webpacker) gem, especially regarding React Server-Side Rendering for better SEO and improved performance.
|
35
43
|
|
36
44
|
## Features and Why React on Rails?
|
37
45
|
|
@@ -47,7 +55,9 @@ Given that `rails/webpacker` gem already provides basic React integration, why w
|
|
47
55
|
|
48
56
|
See [Rails/Webpacker React Integration Options](https://www.shakacode.com/react-on-rails/docs/guides/rails-webpacker-react-integration-options) for comparisons to other gems.
|
49
57
|
|
50
|
-
|
58
|
+
## Online demo
|
59
|
+
* See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
|
60
|
+
* A deployed version of the project `spec/dummy` which demonstrates several uses of `react_on_rails` is available on heroku [through this link](https://ror-spec-dummy.herokuapp.com/)
|
51
61
|
|
52
62
|
## ShakaCode Forum Premium Content
|
53
63
|
_Requires creating a free account._
|
@@ -55,10 +65,9 @@ _Requires creating a free account._
|
|
55
65
|
* [How to use different versions of a file for client and server rendering](https://forum.shakacode.com/t/how-to-use-different-versions-of-a-file-for-client-and-server-rendering/1352)
|
56
66
|
* [How to conditionally render server side based on the device type](https://forum.shakacode.com/t/how-to-conditionally-render-server-side-based-on-the-device-type/1473)
|
57
67
|
|
58
|
-
|
59
68
|
## Prerequisites
|
60
69
|
|
61
|
-
Ruby on Rails >=5
|
70
|
+
Ruby on Rails >=5, rails/webpacker >= 4.2, Ruby >= 2.7
|
62
71
|
|
63
72
|
# Support
|
64
73
|
|
@@ -85,12 +94,12 @@ The following companies support this open source project, and ShakaCode uses the
|
|
85
94
|
[![HoneyBadger](https://user-images.githubusercontent.com/1118459/114100696-63962a00-9860-11eb-8ac1-75ca02856d8e.png)](https://www.honeybadger.io/)
|
86
95
|
[![StatusHero](https://user-images.githubusercontent.com/1118459/126868048-3fe64e54-4d6d-4066-9df2-8cf6fbaeb314.png)](https://statushero.com/)
|
87
96
|
|
88
|
-
ShakaCode's favorite project tracking tool is [
|
97
|
+
ShakaCode's favorite project tracking tool is [Shortcut](https://shortcut.com/). If you want to **try Shortcut and get 2 months free beyond the 14-day trial period**, click [here to use ShakaCode's referral code](http://r.clbh.se/mvfoNeH). We're participating in their awesome triple-sided referral program, which you can read about [here](https://clubhouse.io/referral/). By using our [referral code](http://r.clbh.se/mvfoNeH) you'll be supporting ShakaCode and, thus, React on Rails!
|
89
98
|
|
90
99
|
Aloha and best wishes from Justin and the ShakaCode team!
|
91
100
|
|
92
101
|
# Work with Us
|
93
|
-
ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/career)** to work on our projects, including [HiChee](https://hichee.com)
|
102
|
+
ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/career)** to work on our projects, including [HiChee](https://hichee.com)!
|
94
103
|
|
95
104
|
# License
|
96
105
|
|
data/SUMMARY.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Table of Contents
|
2
2
|
|
3
|
+
Doccumentation for React on Rails has moved!
|
4
|
+
|
5
|
+
Here is the new link:
|
6
|
+
|
7
|
+
**[React on Rails Documentation Link](https://www.shakacode.com/react-on-rails/docs/)**
|
8
|
+
|
9
|
+
-----
|
10
|
+
|
11
|
+
## **OLD DOCS BELOW**
|
3
12
|
+ [Home](./README.md)
|
4
13
|
|
5
14
|
## **Basics**
|
@@ -16,9 +16,20 @@ For more information, see [Using Multiple Buildpacks for an App](https://devcent
|
|
16
16
|
|
17
17
|
### rails/webpacker webpack configuration
|
18
18
|
If you're using the standard rails/webpacker configuration of webpack, then rails/webpacker
|
19
|
-
will automatically modify or create an assets:precompile task to build your assets.
|
19
|
+
will automatically modify or create an assets:precompile task to build your assets.
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
Alternatively, you can specify `config.build_production_command` to have
|
22
|
+
react_on_rails invoke a command for you during assets:precompile.
|
23
|
+
|
24
|
+
```
|
25
|
+
config.build_production_command = "RAILS_ENV=production bin/webpack"
|
26
|
+
```
|
27
|
+
|
28
|
+
### Consider Removing Webpacker's clean task
|
29
|
+
|
30
|
+
If you are deploying on Heroku, then you don't need Webpacker's clean task which
|
31
|
+
might delete files that you need.
|
32
|
+
|
33
|
+
```
|
34
|
+
Rake::Task['webpacker:clean'].clear
|
35
|
+
```
|
@@ -66,15 +66,14 @@ ReactOnRails.configure do |config|
|
|
66
66
|
# defaults to "" (top level)
|
67
67
|
config.node_modules_location = "client" # If using webpacker you should use "".
|
68
68
|
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
69
|
+
# If you're using the standard rails/webpacker configuration of webpack, then rails/webpacker
|
70
|
+
# will automatically modify or create an assets:precompile task to build your assets. If so,
|
71
|
+
# set this value to nil. Alternatively, you can specify `config.build_production_command`
|
72
|
+
# to have react_on_rails invoke a command for you during assets:precompile.
|
73
|
+
# The command is either a script or a module containing a class method `call`
|
74
|
+
# In this example, the module BuildProductionCommand would have a class method `call`.
|
74
75
|
config.build_production_command = "RAILS_ENV=production bin/webpack"
|
75
76
|
|
76
|
-
# Alternatively, you can also specify a module containing a class method `call`
|
77
|
-
# In this example, the module BuildProductionCommand would have a class method `call`.
|
78
77
|
# See bottom for an example of the BuildProductionCommand module.
|
79
78
|
# config.build_production_command = BuildProductionCommand
|
80
79
|
# If you wish to utilize ReactOnRailsPro production bundle caching logic, then use
|
@@ -86,7 +85,7 @@ ReactOnRails.configure do |config|
|
|
86
85
|
# SERVER RENDERING OPTIONS
|
87
86
|
################################################################################
|
88
87
|
# This is the file used for server rendering of React when using `(prerender: true)`
|
89
|
-
# If you are
|
88
|
+
# If you are not using server rendering, you should set this to `nil`.
|
90
89
|
# Note, there is only one server bundle, unlike JavaScript where you want to minimize the size
|
91
90
|
# of the JS sent to the client. For the server rendering, React on Rails creates a pool of
|
92
91
|
# JavaScript execution instances which should handle any component requested.
|
@@ -35,7 +35,6 @@ For example, you might create a [Procfile.dev](https://github.com/shakacode/reac
|
|
35
35
|
On production deployments that use asset precompilation, such as Heroku deployments, `rails/webpacker`, by default, will automatically run webpack to build your JavaScript bundles, running the command `bin/webpack` in your app.
|
36
36
|
|
37
37
|
However, if you want to run a custom command to run webpack to build your bundles, then you will:
|
38
|
-
1. Ensure you do not have a `config/webpack/production.js` file
|
39
38
|
1. Define `config.build_production_command` in your [config/initializers/react_on_rails.rb](https://www.shakacode.com/react-on-rails/docs/guides/configuration/)
|
40
39
|
|
41
40
|
Then React on Rails modifies the `assets:precompile` task to run your `build_production_command`.
|
data/docs/guides/tutorial.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
-----
|
6
6
|
|
7
|
-
*Updated for Ruby 2.7.1, Rails 6.0.3.1,
|
7
|
+
*Updated for Ruby 2.7.1, Rails 6.0.3.1, React on Rails v12.5.0, and Webpacker v6*
|
8
8
|
|
9
9
|
This tutorial guides you through setting up a new or existing Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering.
|
10
10
|
|
@@ -42,7 +42,7 @@ gem install foreman # download and install Foreman
|
|
42
42
|
```
|
43
43
|
|
44
44
|
## Create a new Ruby on Rails App
|
45
|
-
Then we need to create a fresh Rails application
|
45
|
+
Then we need to create a fresh Rails application as following.
|
46
46
|
|
47
47
|
First be sure to run `rails -v` and check you are using Rails 5.1.3 or above. If you are using an older version of Rails, you'll need to install webpacker with react per the instructions [here](https://github.com/rails/webpacker).
|
48
48
|
|
@@ -51,10 +51,9 @@ cd <directory where you want to create your new Rails app>
|
|
51
51
|
|
52
52
|
# Any name you like for the rails app
|
53
53
|
# Skip javascript so will add that next and get the current version
|
54
|
-
rails new --skip-sprockets
|
54
|
+
rails new --skip-sprockets --skip-turbolinks --javascript=webpack test-react-on-rails
|
55
55
|
|
56
56
|
cd test-react-on-rails
|
57
|
-
bundle
|
58
57
|
```
|
59
58
|
|
60
59
|
## Add the webpacker and react_on_rails gems
|
@@ -63,22 +62,21 @@ of both the gem and npm package. In other words, don't use the `^` or `~` in the
|
|
63
62
|
_Use the latest version for react_on_rails._
|
64
63
|
|
65
64
|
```
|
66
|
-
gem 'react_on_rails', '12.0
|
65
|
+
gem 'react_on_rails', '12.5.0' # prefer exact gem version to match npm version
|
67
66
|
```
|
68
67
|
|
69
68
|
Note: The latest released React On Rails version is considered stable. Please use the latest
|
70
69
|
version to ensure you get all the security patches and the best support.
|
71
70
|
|
72
71
|
```bash
|
73
|
-
bundle add webpacker
|
74
|
-
bundle add react_on_rails --version=12.0
|
72
|
+
bundle add webpacker --git=https://github.com/rails/webpacker.git
|
73
|
+
bundle add react_on_rails --version=12.5.0 --strict
|
75
74
|
```
|
76
75
|
|
77
76
|
## Run the webpacker generator
|
78
77
|
|
79
|
-
```
|
78
|
+
```terminal
|
80
79
|
bundle exec rails webpacker:install
|
81
|
-
bundle exec rails webpacker:install:react
|
82
80
|
```
|
83
81
|
|
84
82
|
Let's commit everything before installing React on Rails.
|
@@ -97,20 +95,24 @@ Install React on Rails: `rails generate react_on_rails:install`. You need to fir
|
|
97
95
|
Note, using `redux` is no longer recommended as the basic installer uses React Hooks.
|
98
96
|
If you want the redux install: `rails generate react_on_rails:install --redux`
|
99
97
|
|
98
|
+
The generator will add `mini_racer`'s latest version. If you're using linux & encounter issues installing `libv8`, here's [a common solution](https://github.com/rubyjs/mini_racer/issues/218).
|
99
|
+
|
100
100
|
```
|
101
101
|
rails generate react_on_rails:install
|
102
102
|
```
|
103
103
|
|
104
|
-
|
105
|
-
public/webpack/packs directory.
|
104
|
+
Enter `a` to replace all configuration files required by the project.
|
106
105
|
|
106
|
+
Then run the server with one of the following options:
|
107
|
+
|
108
|
+
## Running with HMR
|
107
109
|
```
|
108
110
|
foreman start -f Procfile.dev
|
109
111
|
```
|
110
112
|
|
111
|
-
##
|
113
|
+
## Running without HMR, statically creating the bundles
|
112
114
|
```
|
113
|
-
foreman start -f Procfile.dev-
|
115
|
+
foreman start -f Procfile.dev-static
|
114
116
|
```
|
115
117
|
|
116
118
|
Visit [http://localhost:3000/hello_world](http://localhost:3000/hello_world) and see your **React On Rails** app running!
|
@@ -250,6 +252,8 @@ heroku open
|
|
250
252
|
|
251
253
|
and you will see your live app and you can share this URL with your friends. Congrats!
|
252
254
|
|
255
|
+
A deployed version of the project `spec/dummy` which demonstrates several uses of `react_on_rails` is available on heroku [through this link](https://ror-spec-dummy.herokuapp.com/)
|
256
|
+
|
253
257
|
## Turning on Server Rendering
|
254
258
|
|
255
259
|
You can turn on server rendering by simply changing the `prerender` option to `true`:
|
@@ -312,7 +316,7 @@ mv app/javascript client
|
|
312
316
|
|
313
317
|
## Using HMR with the rails/webpacker setup
|
314
318
|
|
315
|
-
Start the app using `foreman start -f Procfile.dev
|
319
|
+
Start the app using `foreman start -f Procfile.dev`.
|
316
320
|
|
317
321
|
When you change a JSX file and save, the browser will automatically refresh!
|
318
322
|
|
@@ -33,7 +33,40 @@ module ReactOnRails
|
|
33
33
|
app/views/layouts/hello_world.html.erb
|
34
34
|
config/initializers/react_on_rails.rb
|
35
35
|
Procfile.dev
|
36
|
-
Procfile.dev-
|
36
|
+
Procfile.dev-static]
|
37
|
+
base_files.each { |file| copy_file("#{base_path}#{file}", file) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def copy_js_bundle_files
|
41
|
+
base_path = "base/base/"
|
42
|
+
base_files = %w[app/javascript/packs/server-bundle.js
|
43
|
+
app/javascript/bundles/HelloWorld/components/HelloWorldServer.js
|
44
|
+
app/javascript/bundles/HelloWorld/components/HelloWorld.module.css]
|
45
|
+
base_files.each { |file| copy_file("#{base_path}#{file}", file) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def copy_webpack_config
|
49
|
+
puts "Adding Webpack config"
|
50
|
+
base_path = "base/base"
|
51
|
+
base_files = %w[babel.config.js
|
52
|
+
config/webpack/clientWebpackConfig.js
|
53
|
+
config/webpack/commonWebpackConfig.js
|
54
|
+
config/webpack/development.js
|
55
|
+
config/webpack/production.js
|
56
|
+
config/webpack/serverWebpackConfig.js
|
57
|
+
config/webpack/webpackConfig.js]
|
58
|
+
config = {
|
59
|
+
message: "// The source code including full typescript support is available at:"
|
60
|
+
}
|
61
|
+
base_files.each do |file|
|
62
|
+
template("#{base_path}/#{file}.tt", file, config)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def copy_webpacker_config
|
67
|
+
puts "Adding Webpacker v6 config"
|
68
|
+
base_path = "base/base/"
|
69
|
+
base_files = %w[config/webpacker.yml]
|
37
70
|
base_files.each { |file| copy_file("#{base_path}#{file}", file) }
|
38
71
|
end
|
39
72
|
|
@@ -51,6 +84,16 @@ module ReactOnRails
|
|
51
84
|
puts "Adding the lastest react-on-rails NPM module. Double check this is correct in package.json"
|
52
85
|
run "yarn add react-on-rails --exact"
|
53
86
|
end
|
87
|
+
|
88
|
+
puts "Adding React dependencies"
|
89
|
+
run "yarn add react react-dom @babel/preset-react prop-types babel-plugin-transform-react-remove-prop-types \
|
90
|
+
babel-plugin-macros"
|
91
|
+
|
92
|
+
puts "Adding CSS handlers"
|
93
|
+
run "yarn add css-loader css-minimizer-webpack-plugin mini-css-extract-plugin style-loader"
|
94
|
+
|
95
|
+
puts "Adding dev dependencies"
|
96
|
+
run "yarn add -D @pmmmwh/react-refresh-webpack-plugin react-refresh"
|
54
97
|
end
|
55
98
|
|
56
99
|
def append_to_spec_rails_helper
|
@@ -111,10 +154,10 @@ module ReactOnRails
|
|
111
154
|
- Alternately, you may turn off compile in config/webpacker.yml and run the foreman
|
112
155
|
command to start the rails server and run webpack in watch mode.
|
113
156
|
|
114
|
-
foreman start -f Procfile.dev
|
157
|
+
foreman start -f Procfile.dev-static
|
115
158
|
|
116
159
|
- To turn on HMR, edit config/webpacker.yml and set HMR to true. Restart the rails server
|
117
|
-
and bin/webpack-dev-server. Or use Procfile.dev
|
160
|
+
and bin/webpack-dev-server. Or use Procfile.dev.
|
118
161
|
|
119
162
|
- To server render, change this line app/views/hello_world/index.html.erb to
|
120
163
|
`prerender: true` to see server rendering (right click on page and select "view source").
|
@@ -1,9 +1,5 @@
|
|
1
|
+
# Procfile for development using HMR
|
1
2
|
# You can run these commands in separate shells
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# When making frequent changes to client side assets, you will prefer building webpack assets
|
6
|
-
# upon saving rather than when you refresh your browser page.
|
7
|
-
# Note, if using React on Rails localization you will need to run
|
8
|
-
# `bundle exec rake react_on_rails:locale` before you run bin/webpack
|
9
|
-
client: sh -c 'rm -rf public/packs/* || true && bin/webpack -w'
|
3
|
+
rails: bundle exec rails s -p 3000
|
4
|
+
wp-client: HMR=true bin/webpack-dev-server
|
5
|
+
wp-server: HMR=true SERVER_BUNDLE_ONLY=yes bin/webpack --watch
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# You can run these commands in separate shells
|
2
|
+
web: rails s -p 3000
|
3
|
+
|
4
|
+
# Next line runs a watch process with webpack to compile the changed files.
|
5
|
+
# When making frequent changes to client side assets, you will prefer building webpack assets
|
6
|
+
# upon saving rather than when you refresh your browser page.
|
7
|
+
# Note, if using React on Rails localization you will need to run
|
8
|
+
# `bundle exec rake react_on_rails:locale` before you run bin/webpack
|
9
|
+
webpack: sh -c 'rm -rf public/packs/* || true && bin/webpack -w'
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import PropTypes from 'prop-types';
|
2
2
|
import React, { useState } from 'react';
|
3
|
+
import style from './HelloWorld.module.css';
|
3
4
|
|
4
5
|
const HelloWorld = (props) => {
|
5
6
|
const [name, setName] = useState(props.name);
|
@@ -9,7 +10,7 @@ const HelloWorld = (props) => {
|
|
9
10
|
<h3>Hello, {name}!</h3>
|
10
11
|
<hr />
|
11
12
|
<form>
|
12
|
-
<label htmlFor="name">
|
13
|
+
<label className={style.bright} htmlFor="name">
|
13
14
|
Say hello to:
|
14
15
|
<input id="name" type="text" value={name} onChange={(e) => setName(e.target.value)} />
|
15
16
|
</label>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/babel.config.js") %>
|
2
|
+
|
3
|
+
const defaultConfigFunc = require('@rails/webpacker/package/babel/preset.js');
|
4
|
+
|
5
|
+
module.exports = function (api) {
|
6
|
+
const resultConfig = defaultConfigFunc(api);
|
7
|
+
|
8
|
+
const changesOnDefault = {
|
9
|
+
plugins: [process.env.WEBPACK_SERVE && 'react-refresh/babel'].filter(Boolean),
|
10
|
+
};
|
11
|
+
|
12
|
+
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins];
|
13
|
+
|
14
|
+
return resultConfig;
|
15
|
+
};
|
data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb
CHANGED
@@ -41,5 +41,5 @@ ReactOnRails.configure do |config|
|
|
41
41
|
# different. You should have ONE server bundle which can create all of your server rendered
|
42
42
|
# React components.
|
43
43
|
#
|
44
|
-
config.server_bundle_js_file = "
|
44
|
+
config.server_bundle_js_file = "server-bundle.js"
|
45
45
|
end
|