react_on_rails 11.3.0 → 12.0.0.pre.beta.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +320 -0
  3. data/.eslintignore +2 -1
  4. data/.eslintrc +23 -1
  5. data/.github/FUNDING.yml +1 -0
  6. data/.gitignore +3 -1
  7. data/.prettierignore +10 -1
  8. data/.prettierrc +3 -0
  9. data/.rubocop.yml +37 -11
  10. data/.travis.yml +9 -22
  11. data/CHANGELOG.md +65 -6
  12. data/CONTRIBUTING.md +60 -71
  13. data/Gemfile +3 -4
  14. data/{COMM-LICENSE → REACT-ON-RAILS-PRO-LICENSE} +6 -9
  15. data/README.md +129 -92
  16. data/Rakefile +0 -7
  17. data/SUMMARY.md +7 -11
  18. data/book.json +5 -5
  19. data/docs/additional-reading/asset-pipeline.md +8 -16
  20. data/docs/additional-reading/react-helmet.md +30 -10
  21. data/docs/additional-reading/react-router.md +52 -75
  22. data/docs/additional-reading/server-rendering-tips.md +12 -7
  23. data/docs/api/javascript-api.md +3 -3
  24. data/docs/api/redux-store-api.md +4 -2
  25. data/docs/api/view-helpers-api.md +6 -7
  26. data/docs/basics/configuration.md +83 -69
  27. data/docs/basics/deployment.md +2 -4
  28. data/docs/basics/heroku-deployment.md +24 -0
  29. data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +49 -0
  30. data/docs/basics/i18n.md +45 -23
  31. data/docs/basics/installation-into-an-existing-rails-app.md +4 -9
  32. data/docs/basics/react-server-rendering.md +1 -1
  33. data/docs/basics/recommended-project-structure.md +5 -22
  34. data/docs/basics/{generator-functions-and-railscontext.md → render-functions-and-railscontext.md} +59 -21
  35. data/docs/basics/rspec-configuration.md +27 -16
  36. data/docs/basics/upgrading-react-on-rails.md +58 -2
  37. data/docs/basics/webpack-configuration.md +18 -8
  38. data/docs/contributor-info/errors-with-hooks.md +45 -0
  39. data/docs/contributor-info/pull-requests.md +44 -0
  40. data/docs/misc/doctrine.md +1 -1
  41. data/docs/{misc-pending → outdated}/code-splitting.md +12 -8
  42. data/docs/{basics → outdated}/how-react-on-rails-works.md +8 -4
  43. data/docs/{misc-pending → outdated}/manual-installation-overview.md +5 -5
  44. data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +3 -3
  45. data/docs/{misc-pending → outdated}/rails-assets.md +2 -12
  46. data/docs/{misc → outdated}/rails3.md +0 -0
  47. data/docs/tutorial.md +94 -68
  48. data/jest.config.js +4 -0
  49. data/lib/generators/react_on_rails/base_generator.rb +2 -2
  50. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  51. data/lib/generators/react_on_rails/generator_helper.rb +4 -6
  52. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +3 -1
  53. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +26 -0
  54. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +20 -40
  55. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +4 -1
  56. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +4 -8
  57. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
  58. data/lib/react_on_rails.rb +3 -1
  59. data/lib/react_on_rails/configuration.rb +58 -28
  60. data/lib/react_on_rails/error.rb +2 -0
  61. data/lib/react_on_rails/helper.rb +41 -91
  62. data/lib/react_on_rails/json_parse_error.rb +2 -0
  63. data/lib/react_on_rails/locales/base.rb +150 -0
  64. data/lib/react_on_rails/locales/to_js.rb +37 -0
  65. data/lib/react_on_rails/locales/to_json.rb +27 -0
  66. data/lib/react_on_rails/prerender_error.rb +11 -15
  67. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +41 -46
  68. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +7 -8
  69. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +17 -0
  70. data/lib/react_on_rails/utils.rb +14 -19
  71. data/lib/react_on_rails/version.rb +1 -1
  72. data/lib/react_on_rails/version_checker.rb +1 -0
  73. data/lib/react_on_rails/webpacker_utils.rb +19 -2
  74. data/lib/tasks/assets.rake +33 -46
  75. data/lib/tasks/locale.rake +4 -2
  76. data/package-scripts.yml +11 -8
  77. data/package.json +29 -28
  78. data/rakelib/dummy_apps.rake +1 -9
  79. data/rakelib/example_type.rb +3 -1
  80. data/rakelib/examples.rake +3 -0
  81. data/rakelib/lint.rake +2 -7
  82. data/rakelib/node_package.rake +2 -2
  83. data/rakelib/release.rake +0 -6
  84. data/rakelib/run_rspec.rake +5 -18
  85. data/react_on_rails.gemspec +4 -5
  86. data/tsconfig.json +14 -0
  87. data/webpackConfigLoader.js +3 -2
  88. data/yarn.lock +4333 -2209
  89. metadata +46 -57
  90. data/Gemfile.rails32 +0 -73
  91. data/docs/additional-reading/babel.md +0 -5
  92. data/docs/additional-reading/heroku-deployment.md +0 -92
  93. data/docs/additional-reading/hot-reloading-rails-development-asset-pipeline.md +0 -47
  94. data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
  95. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
  96. data/lib/react_on_rails/assets_precompile.rb +0 -153
  97. data/lib/react_on_rails/locales_to_js.rb +0 -138
@@ -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
- # generated files for development, in /public/webpack/dev
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
- # generated files for tests, in /public/webpack/test
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
- # generated files for tests, in /public/webpack/production
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 overrident for a given call to react_component
58
- config.random_dom_id = false # default is true
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
- # CONFIGURE YOUR SOURCE FILES
97
- # The test helper needs to know where your JavaScript files exist. The default is configured
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
- # You can optionally add values to your rails_context. See example below for RenderingExtension
112
- # config.rendering_extension = RenderingExtension
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
  ################################################################################
@@ -127,27 +89,37 @@ ReactOnRails.configure do |config|
127
89
  # you should include a name that matches your bundle name in your webpack config.
128
90
  config.server_bundle_js_file = "server-bundle.js"
129
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
+
130
105
  # If set to true, this forces Rails to reload the server bundle if it is modified
131
106
  # Default value is Rails.env.development?
132
- #
107
+ # You probably will never change this.
133
108
  config.development_mode = Rails.env.development?
134
109
 
135
- # For server rendering so that it replays in the browser console.
110
+ # For server rendering so that the server-side console replays in the browser console.
136
111
  # This can be set to false so that server side messages are not displayed in the browser.
137
- # 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.
138
113
  # Default value is true
139
- #
140
114
  config.replay_console = true
141
115
 
142
116
  # Default is true. Logs server rendering messages to Rails.logger.info. If false, you'll only
143
117
  # see the server rendering messages in the browser console.
144
- #
145
118
  config.logging_on_server = true
146
119
 
147
120
  # Default is true only for development? to raise exception on server if the JS code throws for
148
121
  # server rendering. The reason is that the server logs will show the error and force you to fix
149
122
  # any server rendering issues immediately during development.
150
- #
151
123
  config.raise_on_prerender_error = Rails.env.development?
152
124
 
153
125
  ################################################################################
@@ -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", "client")
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 generator functions used by the
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
-
@@ -1,6 +1,4 @@
1
1
  # Deployment
2
2
 
3
- - React on Rails puts the necessary precompile steps automatically in the rake precompile step. You can, however, disable this by setting certain values to nil in the [config/initializers/react_on_rails.rb](./configuration.md).
4
- - `build_production_command`: Set to nil to turn off the precompilation of the js assets.
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.
@@ -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
+
@@ -1,23 +1,10 @@
1
- # How to add I18n
1
+ # I18n
2
2
 
3
3
  Here's a summary of adding the I18n functionality.
4
4
 
5
- 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.
5
+ 1. Add `config.i18n_dir` in `config/initializers/react_on_rails.rb`
6
6
 
7
- 1. Add `react-intl` & `intl` to `client/package.json`, and remember to `bundle && yarn install`.
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.js`: All your locales in json format.
35
- `default.js`: Default settings in json format.
21
+ `translations.json`: All your locales in json format.
22
+ `default.json`: Default settings in json format.
36
23
 
37
- 3. Add `translations.js` and `default.js` to your `.gitignore` and `.eslintignore`.
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
- 4. Javascript locale files must be generated before `yarn build`.
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
- Once you setup `config.i18n_dir` as in the previous step, react_on_rails will automatically do this for testing (if using the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets` and for production deployments if using the [default precompile rake hook](../additional-reading/heroku-deployment.md). 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`). 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. 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. The fix is either to 1) run the rake task to build the translations before running the lint command or 2) to run the tests first.
40
+ # Generate locales with react-intl support
42
41
 
43
- 5. In React, you need to initialize `react-intl`, and set parameters for it.
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.1.4" # Update to the current version
11
- gem "webpacker", "~> 3" # Newer versions might be supported
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, f 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).
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](../misc-pending/manual-installation-overview.md) for a concise set summary of what's in a React on Rails installation.
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
-
@@ -10,7 +10,7 @@ During the Rails rendering of HTML per a browser request, the Rails server will
10
10
 
11
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).
12
12
 
13
- See [this note](./how-react-on-rails-works.md#client-side-rendering-vs-server-side-rendering)
13
+ See [this note](docs/outdated/how-react-on-rails-works.md#client-side-rendering-vs-server-side-rendering)
14
14
 
15
15
 
16
16
  ## How do you do Server Rendering with React on Rails?