react_on_rails 11.0.5 → 13.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +338 -0
  3. data/.eslintignore +2 -1
  4. data/.eslintrc +32 -3
  5. data/.github/FUNDING.yml +1 -0
  6. data/.github/ISSUE_TEMPLATE/bug_report.md +23 -0
  7. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  8. data/.github/PULL_REQUEST_TEMPLATE.md +19 -0
  9. data/.github/workflows/lint-js-and-ruby.yml +54 -0
  10. data/.github/workflows/main.yml +183 -0
  11. data/.github/workflows/package-js-tests.yml +35 -0
  12. data/.github/workflows/rspec-package-specs.yml +46 -0
  13. data/.gitignore +3 -4
  14. data/.prettierignore +14 -0
  15. data/.prettierrc +20 -0
  16. data/.rubocop.yml +76 -34
  17. data/.travis.yml +15 -22
  18. data/CHANGELOG.md +443 -55
  19. data/CONTRIBUTING.md +62 -80
  20. data/Gemfile +1 -35
  21. data/Gemfile.development_dependencies +50 -0
  22. data/KUDOS.md +4 -1
  23. data/{docs/LICENSE.md → LICENSE.md} +1 -1
  24. data/NEWS.md +14 -4
  25. data/REACT-ON-RAILS-PRO-LICENSE +95 -0
  26. data/README.md +107 -802
  27. data/Rakefile +1 -8
  28. data/SUMMARY.md +51 -29
  29. data/book.json +5 -5
  30. data/docs/{basics/generator.md → additional-details/generator-details.md} +5 -13
  31. data/docs/{basics/installation-overview.md → additional-details/manual-installation-overview.md} +9 -14
  32. data/docs/{basics → additional-details}/migrating-from-react-rails.md +1 -1
  33. data/docs/additional-details/recommended-project-structure.md +69 -0
  34. data/docs/additional-details/tips-for-usage-with-sp6.md +15 -0
  35. data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +10 -0
  36. data/docs/api/javascript-api.md +35 -6
  37. data/docs/api/redux-store-api.md +102 -0
  38. data/docs/api/view-helpers-api.md +133 -0
  39. data/docs/contributor-info/errors-with-hooks.md +45 -0
  40. data/docs/contributor-info/linters.md +5 -6
  41. data/docs/contributor-info/pull-requests.md +42 -0
  42. data/docs/contributor-info/releasing.md +1 -1
  43. data/docs/deployment/heroku-deployment.md +39 -0
  44. data/docs/getting-started.md +196 -0
  45. data/docs/guides/client-vs-server-rendering.md +27 -0
  46. data/docs/guides/configuration.md +289 -0
  47. data/docs/guides/deployment.md +5 -0
  48. data/docs/guides/file-system-based-automated-bundle-generation.md +197 -0
  49. data/docs/guides/hmr-and-hot-reloading-with-the-webpack-dev-server.md +104 -0
  50. data/docs/guides/how-react-on-rails-works.md +44 -0
  51. data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +40 -0
  52. data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +98 -0
  53. data/docs/guides/i18n.md +87 -0
  54. data/docs/guides/installation-into-an-existing-rails-app.md +66 -0
  55. data/docs/guides/minitest-configuration.md +31 -0
  56. data/docs/guides/rails-webpacker-react-integration-options.md +213 -0
  57. data/docs/guides/react-on-rails-overview.md +29 -0
  58. data/docs/guides/react-server-rendering.md +32 -0
  59. data/docs/guides/render-functions-and-railscontext.md +205 -0
  60. data/docs/guides/rspec-configuration.md +73 -0
  61. data/docs/guides/tutorial.md +371 -0
  62. data/docs/{basics → guides}/upgrading-react-on-rails.md +126 -3
  63. data/docs/guides/webpack-configuration.md +42 -0
  64. data/docs/home.md +23 -0
  65. data/docs/javascript/asset-pipeline.md +12 -0
  66. data/docs/{additional-reading → javascript}/code-splitting.md +21 -11
  67. data/docs/javascript/converting-from-custom-webpack-config-to-rails-webpacker-config.md +10 -0
  68. data/docs/javascript/credits.md +10 -0
  69. data/docs/{additional-reading → javascript}/images.md +5 -6
  70. data/docs/javascript/react-helmet.md +100 -0
  71. data/docs/javascript/react-router.md +90 -0
  72. data/docs/{additional-reading → javascript}/server-rendering-tips.md +15 -12
  73. data/docs/javascript/troubleshooting-when-using-shakapacker.md +77 -0
  74. data/docs/{additional-reading → javascript}/webpack.md +2 -2
  75. data/docs/misc/articles.md +20 -0
  76. data/docs/misc/doctrine.md +5 -6
  77. data/docs/outdated/deferred-rendering.md +39 -0
  78. data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +4 -4
  79. data/docs/{additional-reading → outdated}/rails-assets.md +12 -20
  80. data/docs/{misc → outdated}/rails3.md +2 -2
  81. data/docs/rails/convert-rails-5-api-only-app.md +19 -0
  82. data/docs/rails/rails-engine-integration.md +32 -0
  83. data/docs/{additional-reading → rails}/rails_view_rendering_from_inline_javascript.md +2 -1
  84. data/docs/{additional-reading → rails}/turbolinks.md +13 -1
  85. data/docs/react-on-rails-pro/react-on-rails-pro.md +43 -0
  86. data/docs/testimonials/hvmn.md +25 -0
  87. data/docs/testimonials/resortpass.md +13 -0
  88. data/docs/testimonials/testimonials.md +28 -0
  89. data/jest.config.js +4 -0
  90. data/lib/generators/USAGE +1 -1
  91. data/lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb +41 -0
  92. data/lib/generators/react_on_rails/base_generator.rb +55 -43
  93. data/lib/generators/react_on_rails/bin/dev +30 -0
  94. data/lib/generators/react_on_rails/bin/dev-static +30 -0
  95. data/lib/generators/react_on_rails/dev_tests_generator.rb +4 -3
  96. data/lib/generators/react_on_rails/generator_helper.rb +8 -6
  97. data/lib/generators/react_on_rails/generator_messages.rb +40 -0
  98. data/lib/generators/react_on_rails/install_generator.rb +37 -0
  99. data/lib/generators/react_on_rails/templates/.eslintrc +3 -1
  100. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +4 -6
  101. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +9 -0
  102. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +21 -40
  103. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +4 -0
  104. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorldServer.js +5 -0
  105. data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js +8 -0
  106. data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +2 -1
  107. data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +32 -0
  108. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +20 -4
  109. data/lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml +62 -0
  110. data/lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt +17 -0
  111. data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +17 -0
  112. data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +25 -0
  113. data/lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt +9 -0
  114. data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +117 -0
  115. data/lib/generators/react_on_rails/templates/base/base/config/webpack/test.js.tt +9 -0
  116. data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpack.config.js.tt +15 -0
  117. data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpackConfig.js.tt +36 -0
  118. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +8 -2
  119. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
  120. data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb +2 -2
  121. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +6 -9
  122. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
  123. data/lib/react_on_rails/configuration.rb +198 -145
  124. data/lib/react_on_rails/error.rb +2 -0
  125. data/lib/react_on_rails/git_utils.rb +5 -3
  126. data/lib/react_on_rails/{react_on_rails_helper.rb → helper.rb} +201 -190
  127. data/lib/react_on_rails/json_output.rb +1 -1
  128. data/lib/react_on_rails/json_parse_error.rb +28 -0
  129. data/lib/react_on_rails/locales/base.rb +169 -0
  130. data/lib/react_on_rails/locales/to_js.rb +33 -0
  131. data/lib/react_on_rails/locales/to_json.rb +23 -0
  132. data/lib/react_on_rails/packs_generator.rb +234 -0
  133. data/lib/react_on_rails/prerender_error.rb +35 -27
  134. data/lib/react_on_rails/react_component/render_options.rb +64 -9
  135. data/lib/react_on_rails/server_rendering_js_code.rb +55 -0
  136. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +126 -76
  137. data/lib/react_on_rails/server_rendering_pool.rb +0 -1
  138. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +9 -8
  139. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +17 -0
  140. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +13 -12
  141. data/lib/react_on_rails/test_helper.rb +24 -3
  142. data/lib/react_on_rails/utils.rb +94 -25
  143. data/lib/react_on_rails/version.rb +1 -1
  144. data/lib/react_on_rails/version_checker.rb +5 -1
  145. data/lib/react_on_rails/version_syntax_converter.rb +14 -12
  146. data/lib/react_on_rails/webpacker_utils.rb +105 -5
  147. data/lib/react_on_rails.rb +8 -2
  148. data/lib/tasks/assets.rake +28 -60
  149. data/lib/tasks/generate_packs.rake +11 -0
  150. data/lib/tasks/locale.rake +5 -4
  151. data/package-scripts.yml +49 -0
  152. data/package.json +52 -47
  153. data/rakelib/docker.rake +0 -5
  154. data/rakelib/dummy_apps.rake +5 -8
  155. data/rakelib/example_type.rb +12 -3
  156. data/rakelib/examples.rake +5 -4
  157. data/rakelib/lint.rake +5 -16
  158. data/rakelib/node_package.rake +2 -2
  159. data/rakelib/release.rake +37 -23
  160. data/rakelib/run_rspec.rake +16 -44
  161. data/rakelib/task_helpers.rb +16 -4
  162. data/react_on_rails.gemspec +6 -22
  163. data/tsconfig.json +14 -0
  164. data/webpackConfigLoader.js +5 -4
  165. data/yarn.lock +5935 -3106
  166. metadata +122 -272
  167. data/Gemfile.rails32 +0 -74
  168. data/docs/additional-reading/asset-pipeline.md +0 -20
  169. data/docs/additional-reading/babel.md +0 -5
  170. data/docs/additional-reading/caching-and-performance.md +0 -4
  171. data/docs/additional-reading/heroku-deployment.md +0 -92
  172. data/docs/additional-reading/hot-reloading-rails-development.md +0 -57
  173. data/docs/additional-reading/node-server-rendering.md +0 -5
  174. data/docs/additional-reading/rails-engine-integration.md +0 -34
  175. data/docs/additional-reading/react-helmet.md +0 -80
  176. data/docs/additional-reading/react-router.md +0 -113
  177. data/docs/additional-reading/recommended-project-structure.md +0 -49
  178. data/docs/additional-reading/rspec-configuration.md +0 -56
  179. data/docs/additional-reading/webpack-dev-server.md +0 -15
  180. data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
  181. data/docs/api/ruby-api.md +0 -8
  182. data/docs/basics/configuration.md +0 -163
  183. data/docs/basics/i18n.md +0 -77
  184. data/docs/tutorial.md +0 -220
  185. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
  186. data/lib/react_on_rails/assets_precompile.rb +0 -150
  187. data/lib/react_on_rails/locales_to_js.rb +0 -134
  188. data/ruby-lint.yml +0 -25
  189. /data/docs/{additional-reading → additional-details}/updating-dependencies.md +0 -0
  190. /data/docs/{additional-reading → deployment}/elastic-beanstalk.md +0 -0
  191. /data/docs/{additional-reading → javascript}/angular-js-integration-migration.md +0 -0
  192. /data/docs/{additional-reading → javascript}/capistrano-deployment.md +0 -0
  193. /data/docs/{additional-reading → javascript}/foreman-issues.md +0 -0
  194. /data/docs/{additional-reading → javascript}/node-dependencies-and-npm.md +0 -0
  195. /data/docs/{additional-reading → javascript}/react-and-redux.md +0 -0
  196. /data/docs/{additional-reading → javascript}/troubleshooting-when-using-webpacker.md +0 -0
  197. /data/docs/{additional-reading → javascript}/webpack-v1-notes.md +0 -0
  198. /data/docs/{coding-style → misc}/style.md +0 -0
  199. /data/docs/{additional-reading → misc}/tips.md +0 -0
@@ -0,0 +1,289 @@
1
+ Here is the full set of config options. This file is `/config/initializers/react_on_rails.rb`
2
+
3
+ First, you should have a `/config/shakapacker.yml` setup.
4
+
5
+ Here is the setup when using the recommended `/client` directory for your `node_modules` and source files:
6
+
7
+ ```yaml
8
+ # Note: Base output directory of /public is assumed for static files
9
+ default: &default
10
+ compile: false
11
+ # Used in your webpack configuration. Must be created in the
12
+ # public_output_path folder
13
+ manifest: manifest.json
14
+ cache_manifest: false
15
+
16
+ # Source path is used to check if webpack compilation needs to be run for `compile: true`
17
+ source_path: client/app
18
+
19
+ development:
20
+ <<: *default
21
+ # Generated files for development, in /public/webpack/dev
22
+ public_output_path: webpack/dev
23
+
24
+ test:
25
+ <<: *default
26
+ # Ensure that shakapacker 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
31
+ public_output_path: webpack/test
32
+
33
+ production:
34
+ <<: *default
35
+ # Generated files for production, in /public/webpack/production
36
+ public_output_path: webpack/production
37
+ cache_manifest: true
38
+ ```
39
+
40
+ Here's a representative `/config/initializers/react_on_rails.rb` setup when using this `/client` directory
41
+ for all client files, including your sources and node_modules.
42
+
43
+
44
+ ```ruby
45
+ # frozen_string_literal: true
46
+
47
+ # NOTE: you typically will leave the commented out configurations set to their defaults.
48
+ # Thus, you only need to pay careful attention to the non-commented settings in this file.
49
+ ReactOnRails.configure do |config|
50
+ # You can optionally add values to your rails_context. This object is passed
51
+ # every time a component renders.
52
+ # See below for an example definition of RenderingExtension
53
+ config.rendering_extension = RenderingExtension
54
+
55
+ # `trace`: General debugging flag.
56
+ # The default is true for development, off otherwise.
57
+ # With true, you get detailed logs of rendering and stack traces if you call setTimout,
58
+ # setInterval, clearTimout when server rendering.
59
+ config.trace = Rails.env.development? # default
60
+
61
+ # Configure if default DOM IDs have a random value or are fixed.
62
+ # false ==> Sets the dom id to "#{react_component_name}-react-component"
63
+ # true ==> Adds "-#{SecureRandom.uuid}" to that ID
64
+ # If you might use multiple instances of the same React component on a Rails page, then
65
+ # it is convenient to set this to true or else you have to either manually set the ids to
66
+ # avoid collisions. Most newer apps will have only one instance of a component on a page,
67
+ # so this should be false in most cases.
68
+ # This value can be overridden for a given call to react_component
69
+ config.random_dom_id = true # default
70
+
71
+ # defaults to "" (top level)
72
+ config.node_modules_location = "client" # If using Shakapacker you should use "".
73
+
74
+ # If you're using the standard Shakapacker configuration of webpack, then Shakapacker
75
+ # will automatically modify or create an assets:precompile task to build your assets. If so,
76
+ # set this value to nil. Alternatively, you can specify `config.build_production_command`
77
+ # to have react_on_rails invoke a command for you during assets:precompile.
78
+ # The command is either a script or a module containing a class method `call`
79
+ # In this example, the module BuildProductionCommand would have a class method `call`.
80
+ config.build_production_command = "RAILS_ENV=production bin/shakapacker"
81
+
82
+ # NOTE:
83
+ # When specifying `build_production_command`, you need to disable `rails/shakapacker`
84
+ # configuration by setting `shakapacker_precompile: false` in your `config/shakapacker.yml` file.
85
+
86
+ # See bottom for an example of the BuildProductionCommand module.
87
+ # config.build_production_command = BuildProductionCommand
88
+ # If you wish to utilize ReactOnRailsPro production bundle caching logic, then use
89
+ # config.build_production_command = ReactOnRailsPro::AssetsPrecompile
90
+ # and be sure to check ReactOnRailsPro's configuration documentation!
91
+
92
+ ################################################################################
93
+ ################################################################################
94
+ # SERVER RENDERING OPTIONS
95
+ ################################################################################
96
+ # This is the file used for server rendering of React when using `(prerender: true)`
97
+ # If you are not using server rendering, you should set this to `nil`.
98
+ # Note, there is only one server bundle, unlike JavaScript where you want to minimize the size
99
+ # of the JS sent to the client. For the server rendering, React on Rails creates a pool of
100
+ # JavaScript execution instances which should handle any component requested.
101
+ #
102
+ # While you may configure this to be the same as your client bundle file, this file is typically
103
+ # different. Note, be sure to include the exact file name with the ".js" if you are not hashing this file.
104
+ # If you are hashing this file (supposing you are using the same file for client rendering), then
105
+ # you should include a name that matches your bundle name in your webpack config.
106
+ config.server_bundle_js_file = "server-bundle.js"
107
+
108
+ # `prerender` means server-side rendering
109
+ # default is false. This is an option for view helpers `render_component` and `render_component_hash`.
110
+ # Set to true to change the default value to true.
111
+ config.prerender = false
112
+
113
+ # THE BELOW OPTIONS FOR SERVER-SIDE RENDERING RARELY NEED CHANGING
114
+ #
115
+ # This value only affects server-side rendering when using the webpack-dev-server
116
+ # If you are hashing the server bundle and you want to use the same bundle for client and server,
117
+ # you'd set this to `true` so that React on Rails reads the server bundle from the webpack-dev-server.
118
+ # Normally, you have different bundles for client and server, thus, the default is false.
119
+ # Furthermore, if you are not hashing the server bundle (not in the manifest.json), then React on Rails
120
+ # will only look for the server bundle to be created in the typical file location, typically by
121
+ # a `shakapacker --watch` process.
122
+ # If true, ensure that in config/shakapacker.yml that you have both dev_server.hmr and
123
+ # dev_server.inline set to false.
124
+ config.same_bundle_for_client_and_server = false
125
+
126
+ # If set to true, this forces Rails to reload the server bundle if it is modified
127
+ # Default value is Rails.env.development?
128
+ # You probably will never change this.
129
+ config.development_mode = Rails.env.development?
130
+
131
+ # For server rendering so that the server-side console replays in the browser console.
132
+ # This can be set to false so that server side messages are not displayed in the browser.
133
+ # Default is true. Be cautious about turning this off, as it can make debugging difficult.
134
+ # Default value is true
135
+ config.replay_console = true
136
+
137
+ # Default is true. Logs server rendering messages to Rails.logger.info. If false, you'll only
138
+ # see the server rendering messages in the browser console.
139
+ config.logging_on_server = true
140
+
141
+ # Default is true only for development? to raise exception on server if the JS code throws for
142
+ # server rendering. The reason is that the server logs will show the error and force you to fix
143
+ # any server rendering issues immediately during development.
144
+ config.raise_on_prerender_error = Rails.env.development?
145
+
146
+ # This configuration allows logic to be applied to client rendered props, such as stripping props that are only used during server rendering.
147
+ # Add a module with an adjust_props_for_client_side_hydration method that expects the component's name & props hash
148
+ # See below for an example definition of RenderingPropsExtension
149
+ config.rendering_props_extension = RenderingPropsExtension
150
+
151
+ ################################################################################
152
+ # Server Renderer Configuration for ExecJS
153
+ ################################################################################
154
+ # The default server rendering is ExecJS, by default using Node.js runtime
155
+ # If you wish to use an alternative Node server rendering for higher performance,
156
+ # contact justin@shakacode.com for details.
157
+ #
158
+ # For ExecJS:
159
+ # You can configure your pool of JS virtual machines and specify where it should load code:
160
+ # On MRI, use `node.js` runtime for the best performance
161
+ # (see https://github.com/shakacode/react_on_rails/issues/1438)
162
+ # Also see https://github.com/shakacode/react_on_rails/issues/1457#issuecomment-1165026717 if using `mini_racer`
163
+ # On MRI, you'll get a deadlock with `pool_size` > 1
164
+ # If you're using JRuby, you can increase `pool_size` to have real multi-threaded rendering.
165
+ config.server_renderer_pool_size = 1 # increase if you're on JRuby
166
+ config.server_renderer_timeout = 20 # seconds
167
+
168
+ ################################################################################
169
+ ################################################################################
170
+ # FILE SYSTEM BASED COMPONENT REGISTRY
171
+ # `render_component` and `render_component_hash` view helper methods can
172
+ # auto-load the bundle for the generated component, to avoid having to specify the
173
+ # bundle manually for each view with the component.
174
+ ################################################################################
175
+ # components_subdirectory is the name of the subdirectory matched to detect and register components automatically
176
+ # The default is nil. You can enable the feature by updating it in the next line.
177
+ config.components_subdirectory = nil
178
+ # Change to a value like this example to enable this feature
179
+ # config.components_subdirectory = "ror_components"
180
+
181
+ # Default is false.
182
+ # The default can be overidden as an option in calls to view helpers
183
+ # `render_component` and `render_component_hash`. You may set to true to change the default to auto loading.
184
+ config.auto_load_bundle = false
185
+
186
+ # Default is false
187
+ # Set this to true & instead of trying to import the generated server components into your existing
188
+ # server bundle entrypoint, the PacksGenerator will create a server bundle entrypoint using
189
+ # config.server_bundle_js_file for the filename.
190
+ config.make_generated_server_bundle_the_entrypoint = false
191
+
192
+ # Default is true, which matches Webpacker/Shakapacker's defer default for `append_javascript_pack`
193
+ # Set this to false to have `defer: false` added to your `append_javascript_pack` calls for generated entrypoints.
194
+ config.defer_generated_component_packs = true
195
+
196
+ ################################################################################
197
+ # I18N OPTIONS
198
+ ################################################################################
199
+ # Replace the following line to the location where you keep translation.js & default.js for use
200
+ # by the npm packages react-intl. Be sure this directory exists!
201
+ # config.i18n_dir = Rails.root.join("client", "app", "libs", "i18n")
202
+ #
203
+ # If not using the i18n feature, then leave this section commented out or set the value
204
+ # of config.i18n_dir to nil.
205
+ #
206
+ # Replace the following line to the location where you keep your client i18n yml files
207
+ # that will source for automatic generation on translations.js & default.js
208
+ # By default(without this option) all yaml files from Rails.root.join("config", "locales")
209
+ # and installed gems are loaded
210
+ config.i18n_yml_dir = Rails.root.join("config", "locales")
211
+
212
+ # Possible output formats are js and json
213
+ # The default format is json
214
+ config.i18n_output_format = 'json'
215
+
216
+ ################################################################################
217
+ ################################################################################
218
+ # TEST CONFIGURATION OPTIONS
219
+ # Below options are used with the use of this test helper:
220
+ # ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
221
+ #
222
+ # NOTE:
223
+ # Instead of using this test helper, you may ensure fresh test files using Shakapacker via:
224
+ # 1. Have `config/webpack/test.js` exporting an array of objects to configure both client and server bundles.
225
+ # 2. Set the compile option to true in config/shakapacker.yml for env test
226
+ ################################################################################
227
+
228
+ # If you are using this in your spec_helper.rb (or rails_helper.rb):
229
+ #
230
+ # ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
231
+ #
232
+ # with rspec then this controls what yarn command is run
233
+ # to automatically refresh your webpack assets on every test run.
234
+ #
235
+ config.build_test_command = "RAILS_ENV=test bin/shakapacker"
236
+
237
+ # CONFIGURE YOUR SOURCE FILES
238
+ # The test helper needs to know where your JavaScript files exist. The value is configured
239
+ # by your config/shakapacker.yml source_path:
240
+ # source_path: client/app # if using recommended /client directory
241
+ #
242
+ # Define the files we need to check for webpack compilation when running tests.
243
+ # The default is `%w( manifest.json )` as will be sufficient for most shakapacker builds.
244
+ # However, if you are generating a server bundle that is NOT hashed (present in manifest.json),
245
+ # then include the file in this list like this:
246
+ config.webpack_generated_files = %w( server-bundle.js manifest.json )
247
+ # Note, be sure NOT to include your server-bundle.js if it is hashed, or else React on Rails will
248
+ # think the server-bundle.js is missing every time for test runs.
249
+ end
250
+ ```
251
+
252
+ Example of a ReactOnRailsConfig module for `client_props_extension`:
253
+
254
+ ```ruby
255
+ module RenderingPropsExtension
256
+ # The modify_props method will be called by ReactOnRails::ReactComponent::RenderOptions if config.client_props_extension is defined
257
+ def self.adjust_props_for_client_side_hydration(component_name, props)
258
+ component_name == 'HelloWorld' ? props.except(:server_side_only) : props
259
+ end
260
+ end
261
+ ```
262
+
263
+ Example of a ReactOnRailsConfig module for `production_build_command`:
264
+
265
+ ```ruby
266
+ module BuildProductionCommand
267
+ include FileUtils
268
+ # The call method will be called during assets:precompile
269
+ def self.call
270
+ sh "bin/shakapacker"
271
+ end
272
+ end
273
+ ```
274
+
275
+ Example of a RenderingExtension for custom values in the `rails_context`:
276
+
277
+ ```ruby
278
+ module RenderingExtension
279
+
280
+ # Return a Hash that contains custom values from the view context that will get merged with
281
+ # the standard rails_context values and passed to all calls to Render-Functions used by the
282
+ # react_component and redux_store view helpers
283
+ def self.custom_context(view_context)
284
+ {
285
+ somethingUseful: view_context.session[:something_useful]
286
+ }
287
+ end
288
+ end
289
+ ```
@@ -0,0 +1,5 @@
1
+ # Deployment
2
+
3
+ Shakapacker puts the necessary precompile steps automatically in the rake precompile step.
4
+
5
+ See the [Heroku Deployment](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment/) doc for specifics regarding Heroku. The information for Heroku may apply to other deployments.
@@ -0,0 +1,197 @@
1
+ # File-System-Based Automated Bundle Generation
2
+
3
+ To use the automated bundle generation feature introduced in React on Rails v13.1.0, please upgrade to use [Shakapacker v6.5.1](https://github.com/shakacode/shakapacker/tree/v6.5.1) at least. If you are currently using Webpacker, please follow the migration steps available [v6 upgrade](https://github.com/shakacode/shakapacker/blob/master/docs/v6_upgrade.md). Then upgrade to Shakapacker 7 using [v7 upgrade](https://github.com/shakacode/shakapacker/blob/master/docs/v7_upgrade.md) guide.
4
+
5
+ ## Configuration
6
+
7
+ ### Enable nested_entries for Shakapacker
8
+ To use the automated bundle generation feature, set `nested_entries: true` in the `shakapacker.yml` file like this.
9
+ The generated files will go in a nested directory.
10
+
11
+ ```yml
12
+ default:
13
+ ...
14
+ nested_entries: true
15
+ ```
16
+
17
+ For more details, see [Configuration and Code](https://github.com/shakacode/shakapacker#configuration-and-code) section in [shakapacker](https://github.com/shakacode/shakapacker/).
18
+
19
+ ### Configure Components Subdirectory
20
+ `components_subdirectory` is the name of the matched directories containing components that will be automatically registered for use by the view helpers.
21
+ For example, configure `config/initializers/react_on_rails` to set the name for `components_subdirectory`.·
22
+
23
+ ```rb
24
+ config.components_subdirectory = "ror_components"
25
+ ```
26
+
27
+ Now all React components inside the directories called `ror_components` will automatically be registered for usage with [`react_component`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component) and [`react_component_hash`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component_hash) helper methods provided by React on Rails.
28
+
29
+ ### Configure `auto_load_bundle` Option
30
+
31
+ For automated component registry, [`react_component`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component) and [`react_component_hash`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component_hash) view helper method tries to load generated bundle for component from the generated directory automatically per `auto_load_bundle` option. `auto_load_bundle` option in `config/initializers/react_on_rails` configures the default value that will be passed to component helpers. The default is `false`, and the parameter can be passed explicitly for each call.
32
+
33
+ You can change the value in `config/initializers/react_on_rails` by updating it as follows:
34
+
35
+ ```rb
36
+ config.auto_load_bundle = true
37
+ ```
38
+
39
+ ### Update `.gitignore` file
40
+ React on Rails automatically generates pack files for components to be registered in the `packs/generated` directory. To avoid committing generated files into the version control system, please update `.gitignore` to have
41
+
42
+ ```gitignore
43
+ # Generated React on Rails packs
44
+ app/javascript/packs/generated
45
+ ```
46
+
47
+ *Note: the directory might be different depending on the `source_entry_path` in `config/shakapacker.yml`.*
48
+
49
+ ## Usage
50
+
51
+ ### Basic usage
52
+
53
+ #### Background
54
+ If the `shakapacker.yml` file is configured as instructed [here](https://github.com/shakacode/shakapacker#configuration-and-code), with the following configurations
55
+
56
+ ```yml
57
+ default: &default
58
+ source_path: app/javascript
59
+ source_entry_path: packs
60
+ public_root_path: public
61
+ public_output_path: packs
62
+ nested_entries: true
63
+ # And more
64
+ ```
65
+
66
+ the directory structure will look like this
67
+
68
+ ```
69
+ app/javascript:
70
+ └── packs: # sets up webpack entries
71
+ │ └── application.js # references FooComponentOne.jsx, BarComponentOne.jsx and BarComponentTwo.jsx in `../src`
72
+ └── src: # any directory name is fine. Referenced files need to be under source_path
73
+ │ └── Foo
74
+ │ │ └── ...
75
+ │ │ └── FooComponentOne.jsx
76
+ │ └── Bar
77
+ │ │ └── ...
78
+ │ │ └── BarComponentOne.jsx
79
+ │ │ └── BarComponentTwo.jsx
80
+ └── stylesheets:
81
+ │ └── my_styles.css
82
+ └── images:
83
+ └── logo.svg
84
+ ```
85
+
86
+ Previously, many applications would use one pack (webpack entrypoint) for many components. In this example, the`application.js` file manually registers server components, `FooComponentOne`, `BarComponentOne` and `BarComponentTwo`.
87
+
88
+ ```jsx
89
+ import ReactOnRails from 'react-on-rails';
90
+ import FooComponentOne from '../src/Foo/FooComponentOne';
91
+ import BarComponentOne from '../src/Foo/BarComponentOne';
92
+ import BarComponentTwo from '../src/Foo/BarComponentTwo';
93
+
94
+ ReactOnRails.register({ FooComponentOne, BarComponentOne, BarComponentTwo });
95
+ ```
96
+
97
+ Your layout would contain:
98
+
99
+ ```erb
100
+ <%= javascript_pack_tag 'application' %>
101
+ <%= stylesheet_pack_tag 'application' %>
102
+ ```
103
+
104
+ Now suppose you want to use bundle splitting to minimize unnecessary javascript loaded on each page, you would put each of your components in the `packs` directory.
105
+
106
+ ```
107
+ app/javascript:
108
+ └── packs: # sets up webpack entries
109
+ │ └── FooComponentOne.jsx # Internally uses ReactOnRails.register
110
+ │ └── BarComponentOne.jsx # Internally uses ReactOnRails.register
111
+ │ └── BarComponentTwo.jsx # Internally uses ReactOnRails.register
112
+ └── src: # any directory name is fine. Referenced files need to be under source_path
113
+ │ └── Foo
114
+ │ │ └── ...
115
+ │ └── Bar
116
+ │ │ └── ...
117
+ └── stylesheets:
118
+ │ └── my_styles.css
119
+ └── images:
120
+ └── logo.svg
121
+ ```
122
+
123
+ The tricky part is to figure out which bundles to load on any Rails view. [Shakapacker's `append_stylesheet_pack_tag` and `append_javascript_pack_tag` view helpers](https://github.com/shakacode/shakapacker#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag) enables Rails views to specify needed bundles for use by layout's call to `javascript_pack_tag` and `stylesheet_pack_tag`.
124
+
125
+ #### Solution
126
+
127
+ File-system-based automated pack generation simplifies this process with a new option for the view helpers.
128
+
129
+ For example, if you wanted to utilize our file-system based entrypoint generation for `FooComponentOne` & `BarComponentOne`, but not `BarComponentTwo` (for whatever reason), then...
130
+
131
+ 1. Remove generated entrypoints from parameters passed directly to `javascript_pack_tag` and `stylesheet_pack_tag`.
132
+ 2. Remove generated entrypoints from parameters passed directly to `append_javascript_pack_tag` and `append_stylesheet_pack_tag`.
133
+
134
+ Your layout would now contain:
135
+
136
+ ```erb
137
+ <%= javascript_pack_tag('BarComponentTwo') %>
138
+ <%= stylesheet_pack_tag('BarComponentTwo') %>
139
+ ```
140
+
141
+ 3. Create a directory structure where the components that you want to be auto-generated are within `ReactOnRails.configuration.components_subdirectory`, which should be a subdirectory of `Shakapacker.config.source_path`:
142
+
143
+ ```
144
+ app/javascript:
145
+ └── packs:
146
+ │ └── BarComponentTwo.jsx # Internally uses ReactOnRails.register
147
+ └── src:
148
+ │ └── Foo
149
+ │ │ └── ...
150
+ │ │ └── ror_components # configured as `components_subdirectory`
151
+ │ │ └── FooComponentOne.jsx
152
+ │ └── Bar
153
+ │ │ └── ...
154
+ │ │ └── ror_components # configured as `components_subdirectory`
155
+ │ │ │ └── BarComponentOne.jsx
156
+ │ │ └── something_else
157
+ │ │ │ └── BarComponentTwo.jsx
158
+ ```
159
+
160
+ 4. You no longer need to register the React components within the `ReactOnRails.configuration.components_subdirectory` nor directly add their bundles. For example you can have a Rails view using three components:
161
+
162
+ ```erb
163
+ <% append_javascript_pack('BarComponentTwo') %>
164
+ <%= react_component("FooComponentOne", {}, auto_load_bundle: true) %>
165
+ <%= react_component("BarComponentOne", {}, auto_load_bundle: true) %>
166
+ <%= react_component("BarComponentTwo", {}) %>
167
+ ```
168
+
169
+ If a component uses multiple HTML strings for server rendering, the [`react_component_hash`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component_hash) view helper can be used on the Rails view, as illustrated below.
170
+
171
+ ```erb
172
+ <% foo_component_one_data = react_component_hash("FooComponentOne",
173
+ prerender: true,
174
+ auto_load_bundle: true
175
+ props: {}
176
+ ) %>
177
+ <% content_for :title do %>
178
+ <%= foo_component_one_data['title'] %>
179
+ <% end %>
180
+ <%= foo_component_one_data["componentHtml"] %>
181
+ ```
182
+
183
+ The default value of the `auto_load_bundle` parameter can be specified by setting `config.auto_load_bundle` in `config/initializers/react_on_rails.rb` and thus removed from each call to `react_component`.
184
+
185
+ ### Server Rendering and Client Rendering Components
186
+
187
+ If server rendering is enabled, the component will be registered for usage both in server and client rendering. In order to have separate definitions for client and server rendering, name the component files as `ComponentName.server.jsx` and `ComponentName.client.jsx`. The `ComponentName.server.jsx` file will be used for server rendering and the `ComponentName.client.jsx` file for client rendering. If you don't want the component rendered on the server, you should only have the `ComponentName.client.jsx` file.
188
+
189
+ Once generated, all server entrypoints will be imported into a file named `[ReactOnRails.configuration.server_bundle_js_file]-generated.js`, which in turn will be imported into a source file named the same as `ReactOnRails.configuration.server_bundle_js_file`. If your server bundling logic is such that your server bundle source entrypoint is not named the same as your `ReactOnRails.configuration.server_bundle_js_file` & changing it would be difficult, please let us know.
190
+
191
+ *Note: If specifying separate definitions for client and server rendering, please make sure to delete the generalized `ComponentName.jsx` file.*
192
+
193
+ ### Using Automated Bundle Generation Feature with already defined packs
194
+
195
+ As of version 13.3.4, bundles inside of directories that match `config.components_subdirectory` will be automatically added as entrypoints, while bundles outside of those directories will have to be manually added to the Shakapacker.config.source_entry_path or Webpack's `entry` rules.
196
+
197
+
@@ -0,0 +1,104 @@
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 **Client Side rendering and HMR using react-refresh-webpack-plugin** section bellow or visit [react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin) for additional details.
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/shakapacker-dev-server`
15
+ during development.
16
+
17
+ # Server Side Rendering with the Default shakacode/shakapacker bin/shakapacker-dev-server
18
+
19
+ If you are using server-side rendering, then you have a couple options. The
20
+ recommended technique is to have a different webpack configuration for server
21
+ rendering.
22
+
23
+ ## If you use the same Webpack setup for your server and client bundles
24
+ If you do use the `webpack-dev-server` for prerendering, be sure to set the
25
+ `config/initializers/react_on_rails.rb` setting of
26
+
27
+ ```
28
+ config.same_bundle_for_client_and_server = true
29
+ ```
30
+
31
+ `dev_server.hmr` maps to [devServer.hot](https://webpack.js.org/configuration/dev-server/#devserverhot).
32
+ This must be false if you're using the webpack-dev-server for client and server bundles.
33
+
34
+ `dev_server.inline` maps to [devServer.inline](https://webpack.js.org/configuration/dev-server/#devserverinline).
35
+ This must also be false.
36
+
37
+ If you don't configure these two to false, you'll see errors like:
38
+
39
+ * `"ReferenceError: window is not defined" (if hmr is true)`
40
+ * `"TypeError: Cannot read property 'prototype' of undefined" (if inline is true)`
41
+
42
+ # Client Side rendering with HMR using react-refresh-webpack-plugin
43
+ ## Basic installation
44
+ To enable HMR functionality you have to use `./bin/shakapacker-dev-server`
45
+ 1. In `config/shakapacker.yml` set **hmr** and **inline** `dev_server` properties to true.
46
+ ```
47
+ dev_server:
48
+ https: false
49
+ host: localhost
50
+ port: 3035
51
+ public: localhost:3035
52
+ hmr: true
53
+ # Inline should be set to true if using HMR
54
+ inline: true
55
+ ```
56
+
57
+ 2. Add react refresh packages:
58
+ ` yarn add @pmmmwh/react-refresh-webpack-plugin react-refresh -D`
59
+
60
+ 3. HMR is for use with the `webpack-dev-server`, so we only add this for the `webpack-dev-server`.
61
+ ```
62
+ const { devServer } = require('shakapacker')
63
+
64
+ const isWebpackDevServer = process.env.WEBPACK_DEV_SERVER
65
+
66
+ //plugins
67
+ if (isWebpackDevServer) {
68
+ environment.plugins.append(
69
+ 'ReactRefreshWebpackPlugin',
70
+ new ReactRefreshWebpackPlugin({
71
+ overlay: {
72
+ sockPort: devServer.port
73
+ }
74
+ })
75
+ )
76
+ }
77
+ ```
78
+ We added overlay.sockedPort option in `ReactRefreshWebpackPlugin` to match the webpack dev-server port specified in `config/shakapacker.yml`. Thats way we make sockjs works properly and suppress error in browser console `GET http://localhost:[port]/sockjs-node/info?t=[xxxxxxxxxx] 404 (Not Found)`.
79
+
80
+ 4. Add react-refresh plugin in `babel.config.js`
81
+ ```
82
+ module.export = function(api) {
83
+ return {
84
+ plugins: [process.env.WEBPACK_DEV_SERVER && 'react-refresh/babel'].filter(Boolean)
85
+ }
86
+ }
87
+ ```
88
+ That's it :).
89
+ Now Browser should reflect .js along with .css changes without reloading.
90
+
91
+ If by some reason plugin doesn't work you could revert changes and left only devServer hmr/inline to true affecting only css files.
92
+
93
+ These plugins are working and tested with
94
+ - babel 7
95
+ - webpacker 5
96
+ - bootstrap 4
97
+ - jest 26
98
+ - core-js 3
99
+ - node 12.10.0
100
+ - react-refresh-webpack-plugin@0.4.1
101
+ - react-refresh 0.8.3
102
+ - react_on_rails 11.1.4
103
+
104
+ configuration.
@@ -0,0 +1,44 @@
1
+ # How React on Rails Works (with Shakapcker)
2
+
3
+ *Note, older versions of React on Rails pushed the Webpack bundles through the Asset Pipeline. This older method has *many* disadvantages, such as broken sourcemaps, performance issues, etc. If you need help migrating to the current way of bypassing the Asset Pipeline, [email Justin](mailto:justin@shakacode.com).*
4
+
5
+ Webpack is used to generate JavaScript and CSS "bundles" directly to your `/public` directory. [Shakapacker](https://github.com/shakacode/shakapacker) provides view helpers to access the Webpack-generated (and fingerprinted) JS and CSS. These files totally skip the Rails asset pipeline. You are responsible for properly configuring your Webpack output. You will either use the standard Webpack configuration (*recommended*) or the `shakapacker` setup for Webpack.
6
+
7
+ Ensure these generated bundle files are in your `.gitignore`, as you never want to add the large compiled bundles to git.
8
+
9
+ Inside your Rails views, you can now use the `react_component` helper method provided by React on Rails. You can pass props directly to the react component helper.
10
+
11
+ Optionally, you can also initialize a Redux store with the view or controller helper `redux_store` so that the redux store can be shared amongst multiple React components.
12
+
13
+ ## Client-Side Rendering vs. Server-Side Rendering
14
+
15
+ In most cases, you should use the `prerender: false` (default behavior) with the provided `react_component` helper method to render the React component from your Rails views. In some cases, such as when SEO is vital, or many users will not have JavaScript enabled, you can enable server-rendering by passing `prerender: true` to your helper, or you can simply change the default in `config/initializers/react_on_rails`.
16
+
17
+ Now the server will interpret your JavaScript. The default is to use [ExecJS](https://github.com/rails/execjs) and pass the resulting HTML to the client. If you want to maximize the performance 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).
18
+
19
+ ## HTML Source Code
20
+
21
+ If you open the HTML source of any web page using React on Rails, you'll see the 3 parts of React on Rails rendering:
22
+
23
+ 1. The wrapper div `<div id="HelloWorld-react-component-0">` specifies the div where to place the React rendering. It encloses the server-rendered HTML for the React component. If server rendering is not used (prerender: false), then the major difference is that the HTML rendered for the React component only contains the outer div: `<div id="HelloWorld-react-component-0"/>`. The first specification of the React component is just the same.
24
+ 1. A script tag containing the properties of the React component, such as the registered name and any props. A JavaScript function runs after the page loads, using this data to build and initialize your React components.
25
+ 1. Additional JavaScript is placed to console-log any messages, such as server rendering errors. Note: these server-side logs can be configured only to be sent to the server logs.
26
+
27
+ You can see all this on the source for [reactrails.com](https://www.reactrails.com/)
28
+
29
+ ## Building the Bundles
30
+
31
+ Each time you change your client code, you will need to re-generate the bundles (the webpack-created JavaScript files included in application.js). The included example Foreman `Procfile.dev` files will take care of this for you by starting a webpack process with the watch flag. This will watch your JavaScript code files for changes. Alternatively, the `shakapacker` library also can ensure that your bundles are built.
32
+
33
+ For example, you might create a [Procfile.dev](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/Procfile.dev).
34
+
35
+ On production deployments that use asset precompilation, such as Heroku deployments, `shakapacker`, by default, will automatically run webpack to build your JavaScript bundles, running the command `bin/shakapacker` in your app.
36
+
37
+ However, if you want to run a custom command to run webpack to build your bundles, then you will:
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/)
39
+
40
+ Then React on Rails modifies the `assets:precompile` task to run your `build_production_command`.
41
+
42
+ If you have used the provided generator, these bundles will automatically be added to your `.gitignore` to prevent extraneous noise from re-generated code in your pull requests. You will want to do this manually if you do not use the provided generator.
43
+
44
+ You can stop React on Rails from modifying or creating the `assets:precompile` task, by setting a `REACT_ON_RAILS_PRECOMPILE` environment variable to `no`, `false`, `n` or `f`.