react_on_rails 11.1.4 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +320 -0
- data/.eslintignore +2 -1
- data/.eslintrc +30 -2
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +3 -1
- data/.prettierignore +10 -0
- data/.prettierrc +23 -0
- data/.release-it.json +3 -0
- data/.rubocop.yml +37 -11
- data/.travis.yml +10 -20
- data/CHANGELOG.md +126 -4
- data/CONTRIBUTING.md +61 -80
- data/Gemfile +3 -5
- data/KUDOS.md +4 -1
- data/REACT-ON-RAILS-PRO-LICENSE +95 -0
- data/README.md +148 -89
- data/Rakefile +0 -7
- data/SUMMARY.md +12 -12
- data/book.json +5 -5
- data/docs/additional-reading/asset-pipeline.md +8 -16
- data/docs/additional-reading/images.md +1 -1
- data/docs/additional-reading/rails_view_rendering_from_inline_javascript.md +2 -1
- data/docs/additional-reading/react-helmet.md +30 -10
- data/docs/additional-reading/react-router.md +52 -75
- data/docs/additional-reading/server-rendering-tips.md +12 -7
- data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +10 -0
- data/docs/api/javascript-api.md +3 -3
- data/docs/api/redux-store-api.md +4 -2
- data/docs/api/view-helpers-api.md +17 -14
- data/docs/basics/client-vs-server-rendering.md +8 -2
- data/docs/basics/configuration.md +87 -73
- data/docs/basics/deployment.md +2 -4
- data/docs/basics/generator-details.md +1 -1
- data/docs/basics/heroku-deployment.md +24 -0
- data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +49 -0
- data/docs/basics/i18n.md +45 -23
- data/docs/basics/installation-into-an-existing-rails-app.md +4 -9
- data/docs/basics/minitest-configuration.md +31 -0
- data/docs/basics/react-server-rendering.md +3 -1
- data/docs/basics/recommended-project-structure.md +21 -15
- data/docs/basics/{generator-functions-and-railscontext.md → render-functions-and-railscontext.md} +59 -21
- data/docs/basics/rspec-configuration.md +29 -18
- data/docs/basics/upgrading-react-on-rails.md +74 -3
- data/docs/basics/webpack-configuration.md +29 -8
- data/docs/contributor-info/errors-with-hooks.md +45 -0
- data/docs/contributor-info/pull-requests.md +44 -0
- data/docs/misc/doctrine.md +1 -1
- data/docs/{misc-pending → outdated}/code-splitting.md +13 -9
- data/docs/{basics → outdated}/how-react-on-rails-works.md +8 -4
- data/docs/{misc-pending → outdated}/manual-installation-overview.md +5 -5
- data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +3 -3
- data/docs/{misc-pending → outdated}/rails-assets.md +2 -12
- data/docs/testimonials/hvmn.md +25 -0
- data/docs/testimonials/resortpass.md +13 -0
- data/docs/testimonials/testimonials.md +28 -0
- data/docs/tutorial.md +182 -44
- data/jest.config.js +4 -0
- data/lib/generators/react_on_rails/base_generator.rb +2 -2
- data/lib/generators/react_on_rails/dev_tests_generator.rb +2 -1
- data/lib/generators/react_on_rails/generator_helper.rb +4 -6
- data/lib/generators/react_on_rails/install_generator.rb +2 -0
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +3 -1
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +26 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +20 -40
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +4 -1
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +4 -8
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
- data/lib/react_on_rails/configuration.rb +60 -29
- data/lib/react_on_rails/error.rb +2 -0
- data/lib/react_on_rails/git_utils.rb +2 -0
- data/lib/react_on_rails/helper.rb +110 -159
- data/lib/react_on_rails/json_output.rb +1 -1
- data/lib/react_on_rails/json_parse_error.rb +2 -0
- data/lib/react_on_rails/locales/base.rb +150 -0
- data/lib/react_on_rails/locales/to_js.rb +37 -0
- data/lib/react_on_rails/locales/to_json.rb +27 -0
- data/lib/react_on_rails/prerender_error.rb +11 -15
- data/lib/react_on_rails/react_component/render_options.rb +4 -0
- data/lib/react_on_rails/server_rendering_js_code.rb +42 -0
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +85 -60
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +7 -8
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +17 -0
- data/lib/react_on_rails/utils.rb +19 -20
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/version_checker.rb +5 -1
- data/lib/react_on_rails/webpacker_utils.rb +27 -2
- data/lib/react_on_rails.rb +4 -1
- data/lib/tasks/assets.rake +33 -46
- data/lib/tasks/locale.rake +4 -2
- data/package-scripts.yml +49 -0
- data/package.json +41 -31
- data/rakelib/dummy_apps.rake +1 -9
- data/rakelib/example_type.rb +3 -1
- data/rakelib/examples.rake +3 -0
- data/rakelib/lint.rake +2 -7
- data/rakelib/node_package.rake +2 -2
- data/rakelib/release.rake +3 -8
- data/rakelib/run_rspec.rake +5 -18
- data/react_on_rails.gemspec +4 -5
- data/tsconfig.json +14 -0
- data/webpackConfigLoader.js +5 -4
- data/yarn.lock +7177 -2311
- metadata +54 -55
- data/Gemfile.rails32 +0 -74
- data/docs/additional-reading/babel.md +0 -5
- data/docs/additional-reading/heroku-deployment.md +0 -92
- data/docs/additional-reading/hot-reloading-rails-development.md +0 -57
- data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
- data/docs/testimonials.md +0 -11
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
- data/lib/react_on_rails/assets_precompile.rb +0 -150
- data/lib/react_on_rails/locales_to_js.rb +0 -134
- /data/docs/{misc → outdated}/rails3.md +0 -0
|
@@ -12,21 +12,27 @@ default: &default
|
|
|
12
12
|
# public_output_path folder
|
|
13
13
|
manifest: manifest.json
|
|
14
14
|
cache_manifest: false
|
|
15
|
+
|
|
16
|
+
# Source path is used to check if webpack compilation needs to be run for `compile: true`
|
|
15
17
|
source_path: client/app
|
|
16
18
|
|
|
17
19
|
development:
|
|
18
20
|
<<: *default
|
|
19
|
-
#
|
|
21
|
+
# Generated files for development, in /public/webpack/dev
|
|
20
22
|
public_output_path: webpack/dev
|
|
21
23
|
|
|
22
24
|
test:
|
|
23
25
|
<<: *default
|
|
24
|
-
#
|
|
26
|
+
# Ensure that webpacker invokes webpack to build files for tests if not using the
|
|
27
|
+
# ReactOnRails rspec helper.
|
|
28
|
+
compile: true
|
|
29
|
+
|
|
30
|
+
# Generated files for tests, in /public/webpack/test
|
|
25
31
|
public_output_path: webpack/test
|
|
26
32
|
|
|
27
33
|
production:
|
|
28
34
|
<<: *default
|
|
29
|
-
#
|
|
35
|
+
# Generated files for production, in /public/webpack/production
|
|
30
36
|
public_output_path: webpack/production
|
|
31
37
|
cache_manifest: true
|
|
32
38
|
```
|
|
@@ -45,7 +51,7 @@ ReactOnRails.configure do |config|
|
|
|
45
51
|
# The default is true for development, off otherwise.
|
|
46
52
|
# With true, you get detailed logs of rendering and stack traces if you call setTimout,
|
|
47
53
|
# setInterval, clearTimout when server rendering.
|
|
48
|
-
config.trace = Rails.env.development?
|
|
54
|
+
config.trace = Rails.env.development? # default
|
|
49
55
|
|
|
50
56
|
# Configure if default DOM IDs have a random value or are fixed.
|
|
51
57
|
# false ==> Sets the dom id to "#{react_component_name}-react-component"
|
|
@@ -54,62 +60,18 @@ ReactOnRails.configure do |config|
|
|
|
54
60
|
# it is convenient to set this to true or else you have to either manually set the ids to
|
|
55
61
|
# avoid collisions. Most newer apps will have only one instance of a component on a page,
|
|
56
62
|
# so this should be false in most cases.
|
|
57
|
-
# This value can be
|
|
58
|
-
config.random_dom_id =
|
|
59
|
-
|
|
60
|
-
# defaults to "" (top level)
|
|
61
|
-
#
|
|
62
|
-
config.node_modules_location = "client" # Recommended!
|
|
63
|
-
|
|
64
|
-
# This configures the script to run to build the production assets by webpack. Set this to nil
|
|
65
|
-
# if you don't want react_on_rails building this file for you.
|
|
66
|
-
config.build_production_command = "RAILS_ENV=production bin/webpack"
|
|
67
|
-
|
|
68
|
-
################################################################################
|
|
69
|
-
################################################################################
|
|
70
|
-
# TEST CONFIGURATION OPTIONS
|
|
71
|
-
# Below options are used with the use of this test helper:
|
|
72
|
-
# ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
|
73
|
-
################################################################################
|
|
74
|
-
|
|
75
|
-
# If you are using this in your spec_helper.rb (or rails_helper.rb):
|
|
76
|
-
#
|
|
77
|
-
# ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
|
78
|
-
#
|
|
79
|
-
# with rspec then this controls what yarn command is run
|
|
80
|
-
# to automatically refresh your webpack assets on every test run.
|
|
81
|
-
#
|
|
82
|
-
config.build_test_command = "RAILS_ENV=test bin/webpack"
|
|
83
|
-
|
|
84
|
-
# Directory where your generated assets go. All generated assets must go to the same directory.
|
|
85
|
-
# If you are using webpacker, this value will come from your config/webpacker.yml file.
|
|
86
|
-
# This is the default in webpacker.yml:
|
|
87
|
-
# public_output_path: packs-test
|
|
88
|
-
# which means files in /public/packs-test
|
|
89
|
-
#
|
|
90
|
-
# Alternately, you may configure this if you are NOT using webpacker. It is relative to your Rails
|
|
91
|
-
# root directory. A custom, non-webpacker, config might use something like:
|
|
92
|
-
#
|
|
93
|
-
# config.generated_assets_dir = File.join(%w[public webpack], Rails.env)
|
|
94
|
-
# This setting should not be used if using webpacker.
|
|
63
|
+
# This value can be overridden for a given call to react_component
|
|
64
|
+
config.random_dom_id = true # default
|
|
95
65
|
|
|
96
|
-
#
|
|
97
|
-
|
|
98
|
-
# by your config/webpacker.yml soure_path:
|
|
99
|
-
# source_path: client/app/javascript # if using recommended /client directory
|
|
100
|
-
#
|
|
101
|
-
# If you are not using webpacker, the `node_modules_location` is assumed to be the location of your source
|
|
102
|
-
# files.
|
|
103
|
-
|
|
104
|
-
# Define the files we need to check for webpack compilation when running tests.
|
|
105
|
-
# The default is `%w( manifest.json )` as will be sufficient for most webpacker builds.
|
|
106
|
-
# However, if you are generated a server bundle that is NOT hashed (present in manifest.json),
|
|
107
|
-
# then include the file in this list like this:
|
|
108
|
-
#
|
|
109
|
-
config.webpack_generated_files = %w( server-bundle.js manifest.json )
|
|
66
|
+
# defaults to "" (top level)
|
|
67
|
+
config.node_modules_location = "client" # If using webpacker you should use "".
|
|
110
68
|
|
|
111
|
-
#
|
|
112
|
-
#
|
|
69
|
+
# This configures the script to run to build the production assets by webpack . Set this to nil
|
|
70
|
+
# if you don't want react_on_rails building this file for you.
|
|
71
|
+
# Note, if you want to use this command then you should remove the file
|
|
72
|
+
# config/webpack/production.js
|
|
73
|
+
# If that file exists, React on Rails thinks that you'll use the rails/webpacker bin/webpack compiler.
|
|
74
|
+
config.build_production_command = "RAILS_ENV=production bin/webpack"
|
|
113
75
|
|
|
114
76
|
################################################################################
|
|
115
77
|
################################################################################
|
|
@@ -124,31 +86,41 @@ ReactOnRails.configure do |config|
|
|
|
124
86
|
# While you may configure this to be the same as your client bundle file, this file is typically
|
|
125
87
|
# different. Note, be sure to include the exact file name with the ".js" if you are not hashing this file.
|
|
126
88
|
# If you are hashing this file (supposing you are using the same file for client rendering), then
|
|
127
|
-
#
|
|
128
89
|
# you should include a name that matches your bundle name in your webpack config.
|
|
129
90
|
config.server_bundle_js_file = "server-bundle.js"
|
|
130
91
|
|
|
92
|
+
# THE BELOW OPTIONS FOR SERVER-SIDE RENDERING RARELY NEED CHANGING
|
|
93
|
+
#
|
|
94
|
+
# This value only affects server-side rendering when using the webpack-dev-server
|
|
95
|
+
# If you are hashing the server bundle and you want to use the same bundle for client and server,
|
|
96
|
+
# you'd set this to `true` so that React on Rails reads the server bundle from the webpack-dev-server.
|
|
97
|
+
# Normally, you have different bundles for client and server, thus, the default is false.
|
|
98
|
+
# Furthermore, if you are not hashing the server bundle (not in the manifest.json), then React on Rails
|
|
99
|
+
# will only look for the server bundle to be created in the typical file location, typically by
|
|
100
|
+
# a `webpack --watch` process.
|
|
101
|
+
# If true, ensure that in config/webpacker.yml that you have both dev_server.hmr and
|
|
102
|
+
# dev_server.inline set to false.
|
|
103
|
+
config.same_bundle_for_client_and_server = false
|
|
104
|
+
|
|
131
105
|
# If set to true, this forces Rails to reload the server bundle if it is modified
|
|
132
106
|
# Default value is Rails.env.development?
|
|
133
|
-
#
|
|
107
|
+
# You probably will never change this.
|
|
134
108
|
config.development_mode = Rails.env.development?
|
|
135
109
|
|
|
136
|
-
# For server rendering so that
|
|
110
|
+
# For server rendering so that the server-side console replays in the browser console.
|
|
137
111
|
# This can be set to false so that server side messages are not displayed in the browser.
|
|
138
|
-
# Default is true. Be cautious about turning this off.
|
|
112
|
+
# Default is true. Be cautious about turning this off, as it can make debugging difficult.
|
|
139
113
|
# Default value is true
|
|
140
|
-
#
|
|
141
114
|
config.replay_console = true
|
|
142
115
|
|
|
143
116
|
# Default is true. Logs server rendering messages to Rails.logger.info. If false, you'll only
|
|
144
117
|
# see the server rendering messages in the browser console.
|
|
145
|
-
#
|
|
146
118
|
config.logging_on_server = true
|
|
147
119
|
|
|
148
|
-
# Default is
|
|
149
|
-
#
|
|
150
|
-
#
|
|
151
|
-
config.raise_on_prerender_error =
|
|
120
|
+
# Default is true only for development? to raise exception on server if the JS code throws for
|
|
121
|
+
# server rendering. The reason is that the server logs will show the error and force you to fix
|
|
122
|
+
# any server rendering issues immediately during development.
|
|
123
|
+
config.raise_on_prerender_error = Rails.env.development?
|
|
152
124
|
|
|
153
125
|
################################################################################
|
|
154
126
|
# Server Renderer Configuration for ExecJS
|
|
@@ -172,6 +144,7 @@ ReactOnRails.configure do |config|
|
|
|
172
144
|
# Replace the following line to the location where you keep translation.js & default.js for use
|
|
173
145
|
# by the npm packages react-intl. Be sure this directory exists!
|
|
174
146
|
# config.i18n_dir = Rails.root.join("client", "app", "libs", "i18n")
|
|
147
|
+
#
|
|
175
148
|
# If not using the i18n feature, then leave this section commented out or set the value
|
|
176
149
|
# of config.i18n_dir to nil.
|
|
177
150
|
#
|
|
@@ -179,8 +152,12 @@ ReactOnRails.configure do |config|
|
|
|
179
152
|
# that will source for automatic generation on translations.js & default.js
|
|
180
153
|
# By default(without this option) all yaml files from Rails.root.join("config", "locales")
|
|
181
154
|
# and installed gems are loaded
|
|
182
|
-
config.i18n_yml_dir = Rails.root.join("config", "locales"
|
|
155
|
+
config.i18n_yml_dir = Rails.root.join("config", "locales")
|
|
183
156
|
|
|
157
|
+
# Possible output formats are js and json
|
|
158
|
+
# The default format is json
|
|
159
|
+
config.i18n_output_format = 'json'
|
|
160
|
+
|
|
184
161
|
################################################################################
|
|
185
162
|
################################################################################
|
|
186
163
|
# CLIENT RENDERING OPTIONS
|
|
@@ -189,8 +166,47 @@ ReactOnRails.configure do |config|
|
|
|
189
166
|
################################################################################
|
|
190
167
|
# default is false
|
|
191
168
|
config.prerender = false
|
|
192
|
-
end
|
|
193
169
|
|
|
170
|
+
# You can optionally add values to your rails_context. This object is passed
|
|
171
|
+
# every time a component renders.
|
|
172
|
+
# See example below for an example definition of RenderingExtension
|
|
173
|
+
#
|
|
174
|
+
# config.rendering_extension = RenderingExtension
|
|
175
|
+
|
|
176
|
+
################################################################################
|
|
177
|
+
################################################################################
|
|
178
|
+
# TEST CONFIGURATION OPTIONS
|
|
179
|
+
# Below options are used with the use of this test helper:
|
|
180
|
+
# ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
|
181
|
+
#
|
|
182
|
+
# NOTE:
|
|
183
|
+
# Instead of using this test helper, you may ensure fresh test files using rails/webpacker via:
|
|
184
|
+
# 1. Have `config/webpacker/test.js` exporting an array of objects to configure both client and server bundles.
|
|
185
|
+
# 2. Set the compile option to true in config/webpacker.yml for env test
|
|
186
|
+
################################################################################
|
|
187
|
+
|
|
188
|
+
# If you are using this in your spec_helper.rb (or rails_helper.rb):
|
|
189
|
+
#
|
|
190
|
+
# ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
|
191
|
+
#
|
|
192
|
+
# with rspec then this controls what yarn command is run
|
|
193
|
+
# to automatically refresh your webpack assets on every test run.
|
|
194
|
+
#
|
|
195
|
+
config.build_test_command = "RAILS_ENV=test bin/webpack"
|
|
196
|
+
|
|
197
|
+
# CONFIGURE YOUR SOURCE FILES
|
|
198
|
+
# The test helper needs to know where your JavaScript files exist. The value is configured
|
|
199
|
+
# by your config/webpacker.yml source_path:
|
|
200
|
+
# source_path: client/app # if using recommended /client directory
|
|
201
|
+
#
|
|
202
|
+
# Define the files we need to check for webpack compilation when running tests.
|
|
203
|
+
# The default is `%w( manifest.json )` as will be sufficient for most webpacker builds.
|
|
204
|
+
# However, if you are generated a server bundle that is NOT hashed (present in manifest.json),
|
|
205
|
+
# then include the file in this list like this:
|
|
206
|
+
config.webpack_generated_files = %w( server-bundle.js manifest.json )
|
|
207
|
+
# Note, be sure NOT to include your server-bundle.js if it is hashed, or else React on Rails will
|
|
208
|
+
# think the server-bundle.js is missing every time for test runs.
|
|
209
|
+
end
|
|
194
210
|
```
|
|
195
211
|
|
|
196
212
|
Example of a RenderingExtension for custom values in the `rails_context`:
|
|
@@ -199,7 +215,7 @@ Example of a RenderingExtension for custom values in the `rails_context`:
|
|
|
199
215
|
module RenderingExtension
|
|
200
216
|
|
|
201
217
|
# Return a Hash that contains custom values from the view context that will get merged with
|
|
202
|
-
# the standard rails_context values and passed to all calls to
|
|
218
|
+
# the standard rails_context values and passed to all calls to render functions used by the
|
|
203
219
|
# react_component and redux_store view helpers
|
|
204
220
|
def self.custom_context(view_context)
|
|
205
221
|
{
|
|
@@ -208,5 +224,3 @@ module RenderingExtension
|
|
|
208
224
|
end
|
|
209
225
|
end
|
|
210
226
|
```
|
|
211
|
-
|
|
212
|
-
|
data/docs/basics/deployment.md
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
# Deployment
|
|
2
2
|
|
|
3
|
-
-
|
|
4
|
-
|
|
5
|
-
- `config.symlink_non_digested_assets_regex`: Default is nil, turning off the setup of non-js assets. This should be nil except when when using Sprockets rather than Webpacker.
|
|
6
|
-
- See the [Heroku Deployment](../additional-reading/heroku-deployment.md) doc for specifics regarding Heroku. The information for Heroku may apply to other deployments.
|
|
3
|
+
- `rails/webpacker` puts the necessary precompile steps automatically in the rake precompile step.
|
|
4
|
+
- See the [Heroku Deployment](docs/basics/heroku-deployment.md) doc for specifics regarding Heroku. The information for Heroku may apply to other deployments.
|
|
@@ -44,7 +44,7 @@ More Details:
|
|
|
44
44
|
Another good option is to create a simple test app per the [Tutorial](../tutorial.md).
|
|
45
45
|
|
|
46
46
|
# Understanding the Organization of the Generated Client Code
|
|
47
|
-
The generated client code follows our organization scheme. Each unique set of functionality, is given its own folder inside of `client/app/bundles`. This encourages for modularity of *domains*.
|
|
47
|
+
The generated client code follows our organization scheme. Each unique set of functionality, is given its own folder inside of `app/javascript/app/bundles`. Note, the recommended for bigger projects is `client/app/bundles`. This encourages for modularity of *domains*.
|
|
48
48
|
|
|
49
49
|
Inside of the generated "HelloWorld" domain you will find the following folders:
|
|
50
50
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Heroku Deployment
|
|
2
|
+
## Heroku buildpacks
|
|
3
|
+
|
|
4
|
+
React on Rails requires both a ruby environment (for Rails) and a Node environment (for Webpack), so you will need to have Heroku use multiple buildpacks.
|
|
5
|
+
|
|
6
|
+
Assuming you have downloaded and installed the Heroku command-line utility and have initialized the app, you will need to tell Heroku to use both buildpacks via the command-line:
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
heroku buildpacks:set heroku/ruby
|
|
10
|
+
heroku buildpacks:add --index 1 heroku/nodejs
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For more information, see [Using Multiple Buildpacks for an App](https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app)
|
|
14
|
+
|
|
15
|
+
## assets:precompile
|
|
16
|
+
|
|
17
|
+
### rails/webpacker webpack configuration
|
|
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.
|
|
20
|
+
|
|
21
|
+
### custom webpack configuration
|
|
22
|
+
If you're a custom webpack configuration, and you **do not have the default
|
|
23
|
+
`config/webpack/production.js`** file, then the `config/initializers/react_on_rails.rb`
|
|
24
|
+
configuration `config.build_production_command` will be used.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# HMR and Hot Reloading with the webpack-dev-server
|
|
2
|
+
|
|
3
|
+
The webpack-dev-server provides:
|
|
4
|
+
|
|
5
|
+
1. Speedy compilation of client side assets
|
|
6
|
+
2. Optional HMR which means that the page will reload automatically when after
|
|
7
|
+
compilation completes. Note, some developers do not like this, as you'll
|
|
8
|
+
abruptly lose any tweaks within the Chrome development tools.
|
|
9
|
+
3. Optional hot-reloading. The older react-hot-loader has been deprecated in
|
|
10
|
+
favor of [fast-refresh](https://reactnative.dev/docs/fast-refresh).
|
|
11
|
+
For use with webpack, see [react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin).
|
|
12
|
+
|
|
13
|
+
If you are ***not*** using server-side rendering (***not*** using `prerender: true`),
|
|
14
|
+
then you can follow all the regular docs for using the `bin/webpack-dev-server`
|
|
15
|
+
during development.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# Server Side Rendering with the Default rails/webpacker bin/webpack-dev-server
|
|
19
|
+
|
|
20
|
+
If you are using server-side rendering, then you have a couple options. The
|
|
21
|
+
recommended technique is to have a different webpack configuration for server
|
|
22
|
+
rendering.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## If you use the same Webpack setup for your server and client bundles
|
|
28
|
+
If you do use the webpack-dev-server for prerendering, be sure to set the
|
|
29
|
+
`config/initializers/react_on_rails.rb` setting of
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
config.same_bundle_for_client_and_server = true
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`dev_server.hmr` maps to [devServer.hot](https://webpack.js.org/configuration/dev-server/#devserverhot).
|
|
36
|
+
This must be false if you're using the webpack-dev-server for client and server bundles.
|
|
37
|
+
|
|
38
|
+
`dev_server.inline` maps to [devServer.inline](https://webpack.js.org/configuration/dev-server/#devserverinline).
|
|
39
|
+
This must also be false.
|
|
40
|
+
|
|
41
|
+
If you don't configure these two to false, you'll see errors like:
|
|
42
|
+
|
|
43
|
+
* "ReferenceError: window is not defined" (if hmr is true)
|
|
44
|
+
* "TypeError: Cannot read property 'prototype' of undefined" (if inline is true)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
data/docs/basics/i18n.md
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# I18n
|
|
2
2
|
|
|
3
3
|
Here's a summary of adding the I18n functionality.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
1. Add `config.i18n_dir` in `config/initializers/react_on_rails.rb`
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
```js
|
|
10
|
-
"dependencies": {
|
|
11
|
-
...
|
|
12
|
-
"intl": "^1.2.5",
|
|
13
|
-
"react-intl": "^2.1.5",
|
|
14
|
-
...
|
|
15
|
-
}
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
2. Add `config.i18n_dir` in `config/initializers/react_on_rails.rb`
|
|
19
|
-
|
|
20
|
-
`react-intl` requires locale files in json format. React on Rails will generate `translations.js` & `default.js` automatically after you configured your `config.i18n_dir` in `config/initializers/react_on_rails.rb`.
|
|
7
|
+
React on Rails will generate `translations.json` & `default.json` automatically (see #3) after you configured your `config.i18n_dir` in `config/initializers/react_on_rails.rb`.
|
|
21
8
|
|
|
22
9
|
```ruby
|
|
23
10
|
# Replace the following line to the location where you keep translation.js & default.js.
|
|
@@ -31,16 +18,50 @@ You can refer to [react-webpack-rails-tutorial](https://github.com/shakacode/rea
|
|
|
31
18
|
config.i18n_yml_dir = Rails.root.join("PATH_TO", "YOUR_YAML_I18N_FOLDER")
|
|
32
19
|
```
|
|
33
20
|
|
|
34
|
-
`translations.
|
|
35
|
-
`default.
|
|
21
|
+
`translations.json`: All your locales in json format.
|
|
22
|
+
`default.json`: Default settings in json format.
|
|
36
23
|
|
|
37
|
-
|
|
24
|
+
2. Add `translations.json` and `default.json` to your `.gitignore`.
|
|
25
|
+
|
|
26
|
+
3. Javascript locale files must be generated before `yarn build`.
|
|
38
27
|
|
|
39
|
-
|
|
28
|
+
Once you setup `config.i18n_dir` as in the previous step, you will need to make sure `rake react_on_rails:locale` runs before webpack.
|
|
29
|
+
|
|
30
|
+
For development, you should adjust your startup scripts (Procfiles) so that they run **`bundle exec rake react_on_rails:locale`** before running any webpack watch process (`yarn run build:development`).
|
|
31
|
+
|
|
32
|
+
You may need to configure your CI to run **`bundle exec rake react_on_rails:locale`** before any webpack process if you are not using the React on Rails test helper.
|
|
33
|
+
|
|
34
|
+
Note, if you are try to lint before running tests, and you are depending on the test helper to build your locales, your linting will fail because the translations won't be built yet.
|
|
35
|
+
|
|
36
|
+
The fix is either to
|
|
37
|
+
1) run the rake task to build the translations before running the lint command or
|
|
38
|
+
2) to run the tests first.
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
# Generate locales with react-intl support
|
|
42
41
|
|
|
43
|
-
|
|
42
|
+
By default the locales generated in json format. If you need to generate files in the prior way
|
|
43
|
+
with `react-intl` supported via js files:
|
|
44
|
+
|
|
45
|
+
1. Specify i18n output format in `react_on_rails.rb`:
|
|
46
|
+
```rb
|
|
47
|
+
config.i18n_output_format = 'js'
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
2. Add `react-intl` & `intl` to `client/package.json`, and remember to `bundle && yarn install`.
|
|
51
|
+
Versions should be newer than these:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
"dependencies": {
|
|
55
|
+
...
|
|
56
|
+
"intl": "^1.2.5",
|
|
57
|
+
"react-intl": "^2.1.5",
|
|
58
|
+
...
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
3. Add `translations.js` and `default.js` to your `.gitignore` and `.eslintignore`.
|
|
63
|
+
|
|
64
|
+
4. In React, you need to initialize `react-intl`, and set parameters for it.
|
|
44
65
|
|
|
45
66
|
```js
|
|
46
67
|
...
|
|
@@ -73,5 +94,6 @@ You can refer to [react-webpack-rails-tutorial](https://github.com/shakacode/rea
|
|
|
73
94
|
```
|
|
74
95
|
|
|
75
96
|
# Notes
|
|
76
|
-
|
|
97
|
+
* See why using JSON could be better compare to JS if amount of data is hure [ https://v8.dev/blog/cost-of-javascript-2019#json]( https://v8.dev/blog/cost-of-javascript-2019#json).
|
|
77
98
|
* See [Support for Rails' i18n pluralization #1000](https://github.com/shakacode/react_on_rails/issues/1000) for a discussion of issues around pluralization.
|
|
99
|
+
* *Outdated:* You can refer to [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) and [PR #340](https://github.com/shakacode/react-webpack-rails-tutorial/pull/340), [commmited](https://github.com/shakacode/react-webpack-rails-tutorial/commit/ef369ed9d922aea5116ca7e50208169fd7831389) for a complete example.
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
1. Add the following to your Gemfile and `bundle install`. We recommend fixing the version of React on Rails, as you will need to keep the exact version in sync with the version in your `client/package.json` file.
|
|
8
8
|
|
|
9
9
|
```ruby
|
|
10
|
-
gem "react_on_rails", "
|
|
11
|
-
gem "webpacker", "~>
|
|
10
|
+
gem "react_on_rails", "12.0.0" # Update to the current version
|
|
11
|
+
gem "webpacker", "~> 5"
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
2. Run the following 2 commands to install Webpacker with React. Note,
|
|
14
|
+
2. Run the following 2 commands to install Webpacker with React. Note, if you are using an older version of Rails than 5.1, you'll need to install webpacker with React per the instructions [here](https://github.com/rails/webpacker).
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
```bash
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
|
|
46
46
|
## Installation
|
|
47
47
|
|
|
48
|
-
See the [Installation Overview](
|
|
48
|
+
See the [Installation Overview](docs/outdated/manual-installation-overview.md) for a concise set summary of what's in a React on Rails installation.
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
## NPM
|
|
@@ -57,8 +57,3 @@ $ yarn add react-on-rails --exact
|
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
That will install the latest version and update your package.json. **NOTE:** the `--exact` flag will ensure that you do not have a "~" or "^" for your react-on-rails version in your package.json.
|
|
60
|
-
|
|
61
|
-
## Webpacker Configuration
|
|
62
|
-
|
|
63
|
-
React on Rails users should set configuration value `compile` to false, as React on Rails handles compilation for test and production environments.
|
|
64
|
-
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Minitest Configuration
|
|
2
|
+
|
|
3
|
+
The setup for minitest is the same as for rspec with the following difference.
|
|
4
|
+
|
|
5
|
+
Rather than calling `ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)`, instead you will do something like this:
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
class ActiveSupport::TestCase
|
|
9
|
+
setup do
|
|
10
|
+
ReactOnRails::TestHelper.ensure_assets_compiled
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Or maybe something like this, from the [minitest docs](https://github.com/seattlerb/minitest/blob/master/lib/minitest/test.rb#L119):
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
module MyMinitestPlugin
|
|
20
|
+
def before_setup
|
|
21
|
+
super
|
|
22
|
+
ReactOnRails::TestHelper.ensure_assets_compiled
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class MiniTest::Test
|
|
27
|
+
include MyMinitestPlugin
|
|
28
|
+
end
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# React Server Rendering
|
|
2
2
|
|
|
3
|
+
See also [Client vs. Server Rendering](./client-vs-server-rendering.md)
|
|
4
|
+
|
|
3
5
|
## What is Server Rendering?
|
|
4
6
|
|
|
5
7
|
Here's a [decent article to introduce you to server rendering](https://medium.freecodecamp.org/server-side-rendering-your-react-app-in-three-simple-steps-7a82b95db82e). Note, React on Rails takes care of calling the methods in [ReactDOMServer](https://reactjs.org/docs/react-dom-server.html).
|
|
@@ -8,7 +10,7 @@ During the Rails rendering of HTML per a browser request, the Rails server will
|
|
|
8
10
|
|
|
9
11
|
The default JavaScript interpretter is [ExecJS](https://github.com/rails/execjs). If you want to maximize the perfomance of your server rendering, then you want to use React on Rails Pro which uses NodeJS to do the server rendering. See the [docs for React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
|
|
10
12
|
|
|
11
|
-
See [this note](
|
|
13
|
+
See [this note](docs/outdated/how-react-on-rails-works.md#client-side-rendering-vs-server-side-rendering)
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
## How do you do Server Rendering with React on Rails?
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# Recommended Project structure
|
|
2
2
|
|
|
3
|
-
While React On Rails does not *enforce* a specific project structure, we do *recommend* a standard organization. The more we follow standards as a community, the easier it will be for all of us to move between various Rails projects that include React On Rails.
|
|
4
|
-
|
|
5
3
|
The React on Rails generator uses the standard `rails/webpacker` convention of this structure:
|
|
6
4
|
|
|
7
5
|
```yml
|
|
@@ -14,19 +12,30 @@ app/javascript:
|
|
|
14
12
|
│ └── hello-world-bundle.js
|
|
15
13
|
```
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
However, you may wish to move all your client side files to a single directory called something like `/client`.
|
|
16
|
+
|
|
17
|
+
## Steps to convert from the generator defaults to use a `/client` directory structure.
|
|
18
|
+
|
|
19
|
+
1. Move the directory:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
mv app/javascript client
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
2. Edit your `/config/webpacker.yml` file. Change the `default/source_path`:
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
```yml
|
|
28
|
+
source_path: client
|
|
29
|
+
```
|
|
21
30
|
|
|
22
|
-
|
|
31
|
+
## Moving node_modules from `/` to `/client` with a custom webpack setup.
|
|
23
32
|
|
|
24
|
-
|
|
25
|
-
2. Good enough for very simple projects.
|
|
26
|
-
3. Configuration of Webpack is not the goal of this library, React on Rails.
|
|
33
|
+
`rails/webpacker` probably doesn't support having your main node_modules directory under `/client`, so only follow these steps if you want to use your own webpack configuration.
|
|
27
34
|
|
|
35
|
+
1. Move the `/package.json` to `/client/package.json`
|
|
36
|
+
2. Create a `/package.json` that delegates to `/client/package.json`. See the example in [spec/dummy/package.json](../../spec/dummy/package.json).
|
|
37
|
+
3. See the webpack configuration in [spec/dummy/client](../../spec/dummy/client) for a webpack configuration example.
|
|
28
38
|
|
|
29
|
-
Thus, the generator structure and using rails/webpacker for Webpack configuration **is not recommended** for any commercial projects, especially those that will use server rendering. Instead, the recommended structure is shown in this example app: [github.com/shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) and described below.
|
|
30
39
|
|
|
31
40
|
## JavaScript Assets
|
|
32
41
|
1. `/client`: All client side JavaScript goes under the `/client` directory. Place all the major domains of the client side app under client.
|
|
@@ -34,7 +43,7 @@ Thus, the generator structure and using rails/webpacker for Webpack configuratio
|
|
|
34
43
|
1. `/client/app/bundles`: Top level of different app domains. Use a name within this directory for you app domains. For example, if you had a domain called `widget-editing`, then you would have: `/client/app/bundles/widget-editing`
|
|
35
44
|
1. `/client/app/lib`: Common code for bundles
|
|
36
45
|
1. Within each bundle directory (or the lib directory), such as a domain named "comments"
|
|
37
|
-
`/client/app/bundles/comments`, use following directory structure:
|
|
46
|
+
`/client/app/bundles/comments`, use following directory structure, if you're using redux. However, with React hooks, this will probably be a bit different:
|
|
38
47
|
|
|
39
48
|
* `/actions`: Redux actions.
|
|
40
49
|
* `/components`: "dumb" components (no connections to Redux or Ajax). These get props and can render themselves and children.
|
|
@@ -56,7 +65,7 @@ This isn't really any technique, as you keep handling all your styling assets us
|
|
|
56
65
|
1. Much simpler! There's no changes really from your current processes.
|
|
57
66
|
|
|
58
67
|
### Using Webpack to Manage Styling Assets
|
|
59
|
-
This technique involves customization of the webpack config files to generate CSS, image, and font assets.
|
|
68
|
+
This technique involves customization of the webpack config files to generate CSS, image, and font assets.
|
|
60
69
|
|
|
61
70
|
#### Directory structure
|
|
62
71
|
1. `/client/app/assets`: Assets for CSS for client app.
|
|
@@ -66,6 +75,3 @@ This technique involves customization of the webpack config files to generate CS
|
|
|
66
75
|
1. You can use [CSS modules](https://github.com/css-modules/css-modules), which is super compelling once you seen the benefits.
|
|
67
76
|
1. You can do hot reloading of your assets. Thus, you do not have to refresh your web page to see asset change, including changing styles.
|
|
68
77
|
1. You can run your client code on a mocked out express server for super fast prototyping. In other words, your client application can somewhat more easily be move to a different application server.
|
|
69
|
-
|
|
70
|
-
#### Updates 2017-03-04 Regarding CSS handled by Webpack
|
|
71
|
-
* See article [Best practices for CSS and CSS Modules using Webpack](https://forum.shakacode.com/t/best-practices-for-css-and-css-modules-using-webpack/799).
|