react_on_rails 12.4.0 → 12.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/Gemfile.development_dependencies +2 -1
- data/REACT-ON-RAILS-PRO-LICENSE +1 -1
- data/README.md +17 -5
- 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/server_rendering_js_code.rb +13 -0
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/tasks/assets.rake +6 -7
- data/package.json +1 -1
- data/rakelib/example_type.rb +5 -1
- data/rakelib/examples.rake +7 -2
- data/rakelib/release.rake +1 -1
- data/rakelib/task_helpers.rb +7 -0
- data/react_on_rails.gemspec +1 -1
- metadata +15 -4
- 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: 28e3d2a5f4910c2d0e1aec7d57f2b3d5073cc3317d65dc92d209608d6b305dcd
|
4
|
+
data.tar.gz: f3280cfe4e5e57aeb60da72928a45ff01df41890ee7ab8a018cb6b4fefef61c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ee357656b8bf3fd8367d6036269f8d844c2e6dc72a6133698930dcfae138bfc7312d44d383dcd8d8db20d67da2b110e177374d18322738619ff4de7d43080e4
|
7
|
+
data.tar.gz: 6a291c92e4d2c86d9b1b6c3bac60a2a4980c7b0c876227d53ad741c802f23a1a63c2bcb451b19a89f0c7e8eb583617d42cafc0810d5f3289866e23def0f8fb8c
|
data/CHANGELOG.md
CHANGED
@@ -17,6 +17,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
19
|
|
20
|
+
### [12.5.0] - 2021-12-26
|
21
|
+
|
22
|
+
#### Added
|
23
|
+
- 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).
|
24
|
+
- Supports Rails 7.
|
25
|
+
|
26
|
+
#### Changed
|
27
|
+
- 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).
|
28
|
+
- Minimimum required Ruby is 2.7 to match lastest rails/webpacker.
|
29
|
+
|
20
30
|
### [12.4.0] - 2021-09-22
|
21
31
|
#### Added
|
22
32
|
- ScoutAPM tracing support for server rendering [PR 1379](https://github.com/shakacode/react_on_rails/pull/1379) by [justin808](https://github.com/justin808).
|
@@ -974,7 +984,8 @@ Best done with Object destructing:
|
|
974
984
|
##### Fixed
|
975
985
|
- Fix several generator related issues.
|
976
986
|
|
977
|
-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.
|
987
|
+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.4.0...master
|
988
|
+
[12.4.0]: https://github.com/shakacode/react_on_rails/compare/12.3.0...12.4.0
|
978
989
|
[12.3.0]: https://github.com/shakacode/react_on_rails/compare/12.2.0...12.3.0
|
979
990
|
[12.2.0]: https://github.com/shakacode/react_on_rails/compare/12.1.0...12.2.0
|
980
991
|
[12.1.0]: https://github.com/shakacode/react_on_rails/compare/12.0.4...12.1.0
|
@@ -1,6 +1,6 @@
|
|
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
5
|
gem "rails"
|
6
6
|
gem "sqlite3"
|
@@ -20,6 +20,7 @@ gem "sdoc", group: :doc
|
|
20
20
|
gem "sprockets"
|
21
21
|
|
22
22
|
gem "amazing_print"
|
23
|
+
|
23
24
|
gem "mini_racer"
|
24
25
|
|
25
26
|
group :development, :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,12 +26,12 @@ 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
|
|
@@ -31,7 +39,7 @@ See the documentation at [shakacode.com/react-on-rails/docs](https://www.shakaco
|
|
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
|
|
@@ -49,6 +57,10 @@ See [Rails/Webpacker React Integration Options](https://www.shakacode.com/react-
|
|
49
57
|
|
50
58
|
See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
|
51
59
|
|
60
|
+
## Online demo
|
61
|
+
|
62
|
+
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/)
|
63
|
+
|
52
64
|
## ShakaCode Forum Premium Content
|
53
65
|
_Requires creating a free account._
|
54
66
|
|
@@ -85,12 +97,12 @@ The following companies support this open source project, and ShakaCode uses the
|
|
85
97
|
[![HoneyBadger](https://user-images.githubusercontent.com/1118459/114100696-63962a00-9860-11eb-8ac1-75ca02856d8e.png)](https://www.honeybadger.io/)
|
86
98
|
[![StatusHero](https://user-images.githubusercontent.com/1118459/126868048-3fe64e54-4d6d-4066-9df2-8cf6fbaeb314.png)](https://statushero.com/)
|
87
99
|
|
88
|
-
ShakaCode's favorite project tracking tool is [
|
100
|
+
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
101
|
|
90
102
|
Aloha and best wishes from Justin and the ShakaCode team!
|
91
103
|
|
92
104
|
# 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)
|
105
|
+
ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/career)** to work on our projects, including [HiChee](https://hichee.com)!
|
94
106
|
|
95
107
|
# License
|
96
108
|
|
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
|
data/lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/clientWebpackConfig.js") %>
|
2
|
+
|
3
|
+
const commonWebpackConfig = require('./commonWebpackConfig');
|
4
|
+
|
5
|
+
const configureClient = () => {
|
6
|
+
const clientConfig = commonWebpackConfig();
|
7
|
+
|
8
|
+
// server-bundle is special and should ONLY be built by the serverConfig
|
9
|
+
// In case this entry is not deleted, a very strange "window" not found
|
10
|
+
// error shows referring to window["webpackJsonp"]. That is because the
|
11
|
+
// client config is going to try to load chunks.
|
12
|
+
delete clientConfig.entry['server-bundle'];
|
13
|
+
|
14
|
+
return clientConfig;
|
15
|
+
};
|
16
|
+
|
17
|
+
module.exports = configureClient;
|
data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt
ADDED
@@ -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/config/webpack/commonWebpackConfig.js") %>
|
2
|
+
|
3
|
+
// Common configuration applying to client and server configuration
|
4
|
+
const { webpackConfig: baseClientWebpackConfig, merge } = require('@rails/webpacker');
|
5
|
+
|
6
|
+
const commonOptions = {
|
7
|
+
resolve: {
|
8
|
+
extensions: ['.css', '.ts', '.tsx'],
|
9
|
+
},
|
10
|
+
};
|
11
|
+
|
12
|
+
// Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals
|
13
|
+
const commonWebpackConfig = () => merge({}, baseClientWebpackConfig, commonOptions);
|
14
|
+
|
15
|
+
module.exports = commonWebpackConfig;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/development.js") %>
|
2
|
+
|
3
|
+
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
4
|
+
|
5
|
+
const { devServer, inliningCss } = require('@rails/webpacker');
|
6
|
+
|
7
|
+
const webpackConfig = require('./webpackConfig');
|
8
|
+
|
9
|
+
const developmentEnvOnly = (clientWebpackConfig, _serverWebpackConfig) => {
|
10
|
+
// plugins
|
11
|
+
if (inliningCss) {
|
12
|
+
// Note, when this is run, we're building the server and client bundles in separate processes.
|
13
|
+
// Thus, this plugin is not applied to the server bundle.
|
14
|
+
|
15
|
+
// eslint-disable-next-line global-require
|
16
|
+
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
17
|
+
clientWebpackConfig.plugins.push(
|
18
|
+
new ReactRefreshWebpackPlugin({
|
19
|
+
overlay: {
|
20
|
+
sockPort: devServer.port,
|
21
|
+
},
|
22
|
+
}),
|
23
|
+
);
|
24
|
+
}
|
25
|
+
};
|
26
|
+
|
27
|
+
module.exports = webpackConfig(developmentEnvOnly);
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/production.js") %>
|
2
|
+
|
3
|
+
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
4
|
+
|
5
|
+
const webpackConfig = require('./webpackConfig');
|
6
|
+
|
7
|
+
const productionEnvOnly = (_clientWebpackConfig, _serverWebpackConfig) => {
|
8
|
+
// place any code here that is for production only
|
9
|
+
};
|
10
|
+
|
11
|
+
module.exports = webpackConfig(productionEnvOnly);
|
data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/serverWebpackConfig.js") %>
|
2
|
+
|
3
|
+
const { merge, config } = require('@rails/webpacker');
|
4
|
+
const commonWebpackConfig = require('./commonWebpackConfig');
|
5
|
+
|
6
|
+
const webpack = require('webpack');
|
7
|
+
|
8
|
+
const configureServer = () => {
|
9
|
+
// We need to use "merge" because the clientConfigObject, EVEN after running
|
10
|
+
// toWebpackConfig() is a mutable GLOBAL. Thus any changes, like modifying the
|
11
|
+
// entry value will result in changing the client config!
|
12
|
+
// Using webpack-merge into an empty object avoids this issue.
|
13
|
+
const serverWebpackConfig = commonWebpackConfig();
|
14
|
+
|
15
|
+
// We just want the single server bundle entry
|
16
|
+
const serverEntry = {
|
17
|
+
'server-bundle': serverWebpackConfig.entry['server-bundle'],
|
18
|
+
};
|
19
|
+
|
20
|
+
if (!serverEntry['server-bundle']) {
|
21
|
+
throw new Error(
|
22
|
+
"Create a pack with the file name 'server-bundle.js' containing all the server rendering files",
|
23
|
+
);
|
24
|
+
}
|
25
|
+
|
26
|
+
serverWebpackConfig.entry = serverEntry;
|
27
|
+
|
28
|
+
// Remove the mini-css-extract-plugin from the style loaders because
|
29
|
+
// the client build will handle exporting CSS.
|
30
|
+
// replace file-loader with null-loader
|
31
|
+
serverWebpackConfig.module.rules.forEach((loader) => {
|
32
|
+
if (loader.use && loader.use.filter) {
|
33
|
+
loader.use = loader.use.filter(
|
34
|
+
(item) => !(typeof item === 'string' && item.match(/mini-css-extract-plugin/)),
|
35
|
+
);
|
36
|
+
}
|
37
|
+
});
|
38
|
+
|
39
|
+
// No splitting of chunks for a server bundle
|
40
|
+
serverWebpackConfig.optimization = {
|
41
|
+
minimize: false,
|
42
|
+
};
|
43
|
+
serverWebpackConfig.plugins.unshift(new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }));
|
44
|
+
|
45
|
+
// Custom output for the server-bundle that matches the config in
|
46
|
+
// config/initializers/react_on_rails.rb
|
47
|
+
serverWebpackConfig.output = {
|
48
|
+
filename: 'server-bundle.js',
|
49
|
+
globalObject: 'this',
|
50
|
+
// If using the React on Rails Pro node server renderer, uncomment the next line
|
51
|
+
// libraryTarget: 'commonjs2',
|
52
|
+
path: config.outputPath,
|
53
|
+
publicPath: config.publicPath,
|
54
|
+
// https://webpack.js.org/configuration/output/#outputglobalobject
|
55
|
+
};
|
56
|
+
|
57
|
+
// Don't hash the server bundle b/c would conflict with the client manifest
|
58
|
+
// And no need for the MiniCssExtractPlugin
|
59
|
+
serverWebpackConfig.plugins = serverWebpackConfig.plugins.filter(
|
60
|
+
(plugin) =>
|
61
|
+
plugin.constructor.name !== 'WebpackAssetsManifest' &&
|
62
|
+
plugin.constructor.name !== 'MiniCssExtractPlugin' &&
|
63
|
+
plugin.constructor.name !== 'ForkTsCheckerWebpackPlugin',
|
64
|
+
);
|
65
|
+
|
66
|
+
// Configure loader rules for SSR
|
67
|
+
// Remove the mini-css-extract-plugin from the style loaders because
|
68
|
+
// the client build will handle exporting CSS.
|
69
|
+
// replace file-loader with null-loader
|
70
|
+
const rules = serverWebpackConfig.module.rules;
|
71
|
+
rules.forEach((rule) => {
|
72
|
+
if (Array.isArray(rule.use)) {
|
73
|
+
// remove the mini-css-extract-plugin and style-loader
|
74
|
+
rule.use = rule.use.filter((item) => {
|
75
|
+
let testValue;
|
76
|
+
if (typeof item === 'string') {
|
77
|
+
testValue = item;
|
78
|
+
} else if (typeof item.loader === 'string') {
|
79
|
+
testValue = item.loader;
|
80
|
+
}
|
81
|
+
return !(testValue.match(/mini-css-extract-plugin/) || testValue === 'style-loader');
|
82
|
+
});
|
83
|
+
const cssLoader = rule.use.find((item) => {
|
84
|
+
let testValue;
|
85
|
+
|
86
|
+
if (typeof item === 'string') {
|
87
|
+
testValue = item;
|
88
|
+
} else if (typeof item.loader === 'string') {
|
89
|
+
testValue = item.loader;
|
90
|
+
}
|
91
|
+
|
92
|
+
return testValue.includes('css-loader');
|
93
|
+
});
|
94
|
+
if (cssLoader && cssLoader.options) {
|
95
|
+
cssLoader.options.modules = { exportOnlyLocals: true };
|
96
|
+
}
|
97
|
+
|
98
|
+
// Skip writing image files during SSR by setting emitFile to false
|
99
|
+
} else if (rule.use && (rule.use.loader === 'url-loader' || rule.use.loader === 'file-loader')) {
|
100
|
+
rule.use.options.emitFile = false;
|
101
|
+
}
|
102
|
+
});
|
103
|
+
|
104
|
+
// eval works well for the SSR bundle because it's the fastest and shows
|
105
|
+
// lines in the server bundle which is good for debugging SSR
|
106
|
+
// The default of cheap-module-source-map is slow and provides poor info.
|
107
|
+
serverWebpackConfig.devtool = 'eval';
|
108
|
+
|
109
|
+
// If using the default 'web', then libraries like Emotion and loadable-components
|
110
|
+
// break with SSR. The fix is to use a node renderer and change the target.
|
111
|
+
// If using the React on Rails Pro node server renderer, uncomment the next line
|
112
|
+
// serverWebpackConfig.target = 'node'
|
113
|
+
|
114
|
+
return serverWebpackConfig;
|
115
|
+
};
|
116
|
+
|
117
|
+
module.exports = configureServer;
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/webpackConfig.js") %>
|
2
|
+
|
3
|
+
const clientWebpackConfig = require('./clientWebpackConfig');
|
4
|
+
const serverWebpackConfig = require('./serverWebpackConfig');
|
5
|
+
|
6
|
+
const webpackConfig = (envSpecific) => {
|
7
|
+
const clientConfig = clientWebpackConfig();
|
8
|
+
const serverConfig = serverWebpackConfig();
|
9
|
+
|
10
|
+
if (envSpecific) {
|
11
|
+
envSpecific(clientConfig, serverConfig);
|
12
|
+
}
|
13
|
+
|
14
|
+
let result;
|
15
|
+
// For HMR, need to separate the the client and server webpack configurations
|
16
|
+
if (process.env.WEBPACK_SERVE || process.env.CLIENT_BUNDLE_ONLY) {
|
17
|
+
// eslint-disable-next-line no-console
|
18
|
+
console.log('[React on Rails] Creating only the client bundles.');
|
19
|
+
result = clientConfig;
|
20
|
+
} else if (process.env.SERVER_BUNDLE_ONLY) {
|
21
|
+
// eslint-disable-next-line no-console
|
22
|
+
console.log('[React on Rails] Creating only the server bundle.');
|
23
|
+
result = serverConfig;
|
24
|
+
} else {
|
25
|
+
// default is the standard client and server build
|
26
|
+
// eslint-disable-next-line no-console
|
27
|
+
console.log('[React on Rails] Creating both client and server bundles.');
|
28
|
+
result = [clientConfig, serverConfig];
|
29
|
+
}
|
30
|
+
|
31
|
+
// To debug, uncomment next line and inspect "result"
|
32
|
+
// debugger
|
33
|
+
return result;
|
34
|
+
};
|
35
|
+
|
36
|
+
module.exports = webpackConfig;
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Note: You must restart bin/webpack-dev-server for changes to take effect
|
2
|
+
|
3
|
+
default: &default
|
4
|
+
source_path: app/javascript
|
5
|
+
source_entry_path: packs
|
6
|
+
public_root_path: public
|
7
|
+
public_output_path: packs
|
8
|
+
cache_path: tmp/webpacker
|
9
|
+
webpack_compile_output: true
|
10
|
+
|
11
|
+
# Additional paths webpack should lookup modules
|
12
|
+
# ['app/assets', 'engine/foo/app/assets']
|
13
|
+
additional_paths: []
|
14
|
+
|
15
|
+
# Reload manifest.json on all requests so we reload latest compiled packs
|
16
|
+
cache_manifest: false
|
17
|
+
|
18
|
+
development:
|
19
|
+
<<: *default
|
20
|
+
# This is false since we're running `bin/webpack -w` in Procfile.dev-setic
|
21
|
+
compile: false
|
22
|
+
|
23
|
+
# Reference: https://webpack.js.org/configuration/dev-server/
|
24
|
+
dev_server:
|
25
|
+
https: false
|
26
|
+
host: localhost
|
27
|
+
port: 3035
|
28
|
+
# Hot Module Replacement updates modules while the application is running without a full reload
|
29
|
+
hmr: true
|
30
|
+
client:
|
31
|
+
# Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
|
32
|
+
overlay: true
|
33
|
+
# May also be a string
|
34
|
+
# webSocketURL:
|
35
|
+
# hostname: "0.0.0.0"
|
36
|
+
# pathname: "/ws"
|
37
|
+
# port: 8080
|
38
|
+
compress: true
|
39
|
+
# Note that apps that do not check the host are vulnerable to DNS rebinding attacks
|
40
|
+
allowed_hosts: [ 'localhost' ]
|
41
|
+
pretty: true
|
42
|
+
headers:
|
43
|
+
'Access-Control-Allow-Origin': '*'
|
44
|
+
static:
|
45
|
+
watch:
|
46
|
+
ignored: '**/node_modules/**'
|
47
|
+
|
48
|
+
test:
|
49
|
+
<<: *default
|
50
|
+
compile: true
|
51
|
+
|
52
|
+
# Compile test packs to a separate directory
|
53
|
+
public_output_path: packs-test
|
54
|
+
|
55
|
+
production:
|
56
|
+
<<: *default
|
57
|
+
|
58
|
+
# Production depends on precompilation of packs prior to booting for performance.
|
59
|
+
compile: false
|
60
|
+
|
61
|
+
# Cache manifest.json for performance
|
62
|
+
cache_manifest: true
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import PropTypes from 'prop-types';
|
2
2
|
import React from 'react';
|
3
|
+
import style from './HelloWorld.module.css';
|
3
4
|
|
4
5
|
const HelloWorld = ({ name, updateName }) => (
|
5
6
|
<div>
|
@@ -9,7 +10,7 @@ const HelloWorld = ({ name, updateName }) => (
|
|
9
10
|
</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) => updateName(e.target.value)} />
|
15
16
|
</label>
|
@@ -18,6 +18,19 @@ module ReactOnRails
|
|
18
18
|
react_component_name: nil,
|
19
19
|
render_options: nil
|
20
20
|
)
|
21
|
+
|
22
|
+
config_server_bundle_js = ReactOnRails.configuration.server_bundle_js_file
|
23
|
+
|
24
|
+
if render_options.prerender == true && config_server_bundle_js.blank?
|
25
|
+
msg = <<~MSG
|
26
|
+
The `prerender` option to allow Server Side Rendering is marked as true but the ReactOnRails configuration
|
27
|
+
for `server_bundle_js_file` is nil or not present in `config/initializers/react_on_rails.rb`.
|
28
|
+
Set `config.server_bundle_js_file` to your javascript bundle to allow server side rendering.
|
29
|
+
Read more at https://www.shakacode.com/react-on-rails/docs/guides/react-server-rendering/
|
30
|
+
MSG
|
31
|
+
raise ReactOnRails::Error, msg
|
32
|
+
end
|
33
|
+
|
21
34
|
js_code_renderer.render(props_string, rails_context, redux_stores, react_component_name, render_options)
|
22
35
|
end
|
23
36
|
|
data/lib/tasks/assets.rake
CHANGED
@@ -9,7 +9,7 @@ ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
|
|
9
9
|
|
10
10
|
skip_react_on_rails_precompile = %w[no false n f].include?(ENV["REACT_ON_RAILS_PRECOMPILE"])
|
11
11
|
|
12
|
-
if !skip_react_on_rails_precompile &&
|
12
|
+
if !skip_react_on_rails_precompile && ReactOnRails.configuration.build_production_command.present?
|
13
13
|
# Ensure that rails/webpacker does not call bin/webpack if we're providing
|
14
14
|
# the build command.
|
15
15
|
ENV["WEBPACKER_PRECOMPILE"] = "false"
|
@@ -40,12 +40,10 @@ end
|
|
40
40
|
# rubocop:disable Metrics/BlockLength
|
41
41
|
namespace :react_on_rails do
|
42
42
|
namespace :assets do
|
43
|
-
desc
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
Note: This command is not automatically added to assets:precompile if the rails/webpacker
|
48
|
-
configuration file config/webpack/production.js exists.
|
43
|
+
desc <<~DESC.strip_heredoc
|
44
|
+
If config.build_production_command is defined, this command is automatically
|
45
|
+
added to task assets:precompile and the regular webpacker compile will not run.
|
46
|
+
The defined command is either a script or a module with a method `call`.
|
49
47
|
DESC
|
50
48
|
task webpack: :locale do
|
51
49
|
build_production_command = ReactOnRails.configuration.build_production_command
|
@@ -63,6 +61,7 @@ namespace :react_on_rails do
|
|
63
61
|
exit!(1)
|
64
62
|
end
|
65
63
|
else
|
64
|
+
# Left in this warning message in case this rake task is run directly
|
66
65
|
msg = <<~MSG
|
67
66
|
React on Rails is aborting webpack compilation from task react_on_rails:assets:webpack
|
68
67
|
because you do not have the `config.build_production_command` defined.
|
data/package.json
CHANGED
data/rakelib/example_type.rb
CHANGED
@@ -52,7 +52,11 @@ module ReactOnRails
|
|
52
52
|
attr_writer :rails_options
|
53
53
|
|
54
54
|
def rails_options
|
55
|
-
@rails_options ||=
|
55
|
+
@rails_options ||= if ReactOnRails::Utils.rails_version_less_than("7.0")
|
56
|
+
"--skip-bundle --skip-spring --skip-git --skip-test-unit --skip-active-record -J"
|
57
|
+
else
|
58
|
+
"--skip-bundle --skip-spring --skip-git --skip-test-unit --skip-active-record -j webpack"
|
59
|
+
end
|
56
60
|
end
|
57
61
|
|
58
62
|
%w[gen clobber npm_install build_webpack_bundles].each do |task_type|
|
data/rakelib/examples.rake
CHANGED
@@ -30,12 +30,17 @@ namespace :examples do # rubocop:disable Metrics/BlockLength
|
|
30
30
|
desc "Generates #{example_type.name_pretty}"
|
31
31
|
task example_type.gen_task_name_short => example_type.clobber_task_name do
|
32
32
|
mkdir_p(example_type.dir)
|
33
|
-
|
33
|
+
if Rails::VERSION::MAJOR < 6
|
34
|
+
example_type.rails_options += " --webpack"
|
35
|
+
elsif Rails::VERSION::MAJOR >= 7
|
36
|
+
example_type.rails_options += "--javascript=webpack"
|
37
|
+
end
|
34
38
|
sh_in_dir(examples_dir, "rails new #{example_type.name} #{example_type.rails_options}")
|
35
39
|
sh_in_dir(example_type.dir, "touch .gitignore")
|
40
|
+
copy_generator_webpacker_yml_to(example_type.dir)
|
41
|
+
sh_in_dir(example_type.dir, "bundle add webpacker --version 6.0.0.rc.6")
|
36
42
|
sh_in_dir(example_type.dir, "rake webpacker:install")
|
37
43
|
sh_in_dir(example_type.dir, "bundle binstubs --path=#{example_type.dir}/bin webpacker")
|
38
|
-
sh_in_dir(example_type.dir, "rake webpacker:install:react")
|
39
44
|
append_to_gemfile(example_type.gemfile, example_type.required_gems)
|
40
45
|
bundle_install_in(example_type.dir)
|
41
46
|
sh_in_dir(example_type.dir, example_type.generator_shell_commands)
|
data/rakelib/release.rake
CHANGED
@@ -60,7 +60,7 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
|
|
60
60
|
# Will bump the yarn version, commit, tag the commit, push to repo, and release on yarn
|
61
61
|
release_it_command = +"release-it"
|
62
62
|
release_it_command << " #{npm_version}" unless npm_version.strip.empty?
|
63
|
-
release_it_command << " --
|
63
|
+
release_it_command << " --npm.publish --no-git.requireCleanWorkingDir"
|
64
64
|
release_it_command << " --dry-run --verbose" if is_dry_run
|
65
65
|
sh_in_dir(gem_root, release_it_command)
|
66
66
|
|
data/rakelib/task_helpers.rb
CHANGED
@@ -12,6 +12,13 @@ module ReactOnRails
|
|
12
12
|
File.join(gem_root, "gen-examples", "examples")
|
13
13
|
end
|
14
14
|
|
15
|
+
# This method is used to prevent an error that when installing webpacker 6.0.0.rc.6
|
16
|
+
# without a previous config/webpacker.yml will throw and error
|
17
|
+
def copy_generator_webpacker_yml_to(destination)
|
18
|
+
webpacker_file = File.join(gem_root, "lib/generators/react_on_rails/templates/base/base/config/webpacker.yml")
|
19
|
+
sh %( cp #{webpacker_file} #{destination}/config/webpacker.yml )
|
20
|
+
end
|
21
|
+
|
15
22
|
def dummy_app_dir
|
16
23
|
File.join(gem_root, "spec/dummy")
|
17
24
|
end
|
data/react_on_rails.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
s.require_paths = ["lib"]
|
25
25
|
|
26
|
-
s.required_ruby_version = ">= 2.
|
26
|
+
s.required_ruby_version = ">= 2.7.0"
|
27
27
|
|
28
28
|
s.add_dependency "addressable"
|
29
29
|
s.add_dependency "connection_pool"
|
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: 12.
|
4
|
+
version: 12.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -244,13 +244,24 @@ files:
|
|
244
244
|
- lib/generators/react_on_rails/react_with_redux_generator.rb
|
245
245
|
- lib/generators/react_on_rails/templates/.eslintrc
|
246
246
|
- lib/generators/react_on_rails/templates/base/base/Procfile.dev
|
247
|
-
- lib/generators/react_on_rails/templates/base/base/Procfile.dev-
|
247
|
+
- lib/generators/react_on_rails/templates/base/base/Procfile.dev-static
|
248
248
|
- lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rb
|
249
249
|
- lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx
|
250
|
+
- lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css
|
251
|
+
- lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorldServer.js
|
250
252
|
- lib/generators/react_on_rails/templates/base/base/app/javascript/packs/registration.js.tt
|
253
|
+
- lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js
|
251
254
|
- lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt
|
252
255
|
- lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb
|
256
|
+
- lib/generators/react_on_rails/templates/base/base/babel.config.js.tt
|
253
257
|
- lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb
|
258
|
+
- lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt
|
259
|
+
- lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt
|
260
|
+
- lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt
|
261
|
+
- lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt
|
262
|
+
- lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt
|
263
|
+
- lib/generators/react_on_rails/templates/base/base/config/webpack/webpackConfig.js.tt
|
264
|
+
- lib/generators/react_on_rails/templates/base/base/config/webpacker.yml
|
254
265
|
- lib/generators/react_on_rails/templates/dev_tests/.eslintrc
|
255
266
|
- lib/generators/react_on_rails/templates/dev_tests/.rspec
|
256
267
|
- lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb
|
@@ -330,7 +341,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
330
341
|
requirements:
|
331
342
|
- - ">="
|
332
343
|
- !ruby/object:Gem::Version
|
333
|
-
version: 2.
|
344
|
+
version: 2.7.0
|
334
345
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
335
346
|
requirements:
|
336
347
|
- - ">="
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# Procfile for development using HMR
|
2
|
-
|
3
|
-
web: rails s -p 3000
|
4
|
-
|
5
|
-
# Note, hot and live reloading don't work with the default generator setup on
|
6
|
-
# top of the rails/webpacker Webpack config with server rendering.
|
7
|
-
# If you have server rendering enabled (prerender is true), you either need to
|
8
|
-
# a. Ensure that you have dev_server.hmr and dev_server.inline BOTH set to false,
|
9
|
-
# and you have this option in your config/initializers/react_on_rails.rb:
|
10
|
-
# config.same_bundle_for_client_and_server = true
|
11
|
-
# If you have either config/webpacker.yml option set to true, you'll see errors like
|
12
|
-
# "ReferenceError: window is not defined" (if hmr is true)
|
13
|
-
# "TypeError: Cannot read property 'prototype' of undefined" (if inline is true)
|
14
|
-
# b. Skip using the webpack-dev-server. bin/webpack --watch is typically
|
15
|
-
fast enough.
|
16
|
-
# c. See the React on Rails README for a link to documentation for how to setup
|
17
|
-
# SSR with HMR and React hot loading using the webpack-dev-server only for the
|
18
|
-
# client bundles and a static file for the server bundle.
|
19
|
-
|
20
|
-
# Run the webpack-dev-server for client and maybe server files
|
21
|
-
webpack-dev-server: bin/webpack-dev-server
|
22
|
-
|
23
|
-
# Keep the JS fresh for server rendering. Remove if not server rendering.
|
24
|
-
# Especially if you have not configured generation of a server bundle without a hash.
|
25
|
-
# as that will conflict with the manifest created by the bin/webpack-dev-server
|
26
|
-
# rails-server-assets: SERVER_BUNDLE_ONLY=yes bin/webpack --watch
|