|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 |
| -# See https://github.com/shakacode/react_on_rails/blob/master/docs/guides/configuration.md |
4 |
| -# for many more options. |
5 |
| - |
| 3 | +# Shown below are the defaults for configuration |
6 | 4 | ReactOnRails.configure do |config|
|
7 |
| - # This configures the script to run to build the production assets by webpack. Set this to nil |
8 |
| - # if you don't want react_on_rails building this file for you. |
9 |
| - # If nil, then the standard shakacode/shakapacker assets:precompile will run |
10 |
| - # config.build_production_command = nil |
| 5 | + # Define the files for we need to check for webpack compilation when running tests |
| 6 | + config.webpack_generated_files = %w[client-bundle.js server-bundle.js] |
11 | 7 |
|
12 |
| - ################################################################################ |
13 |
| - ################################################################################ |
14 |
| - # TEST CONFIGURATION OPTIONS |
15 |
| - # Below options are used with the use of this test helper: |
16 |
| - # ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config) |
17 |
| - ################################################################################ |
| 8 | + config.build_test_command = "RAILS_ENV=test bin/shakapacker" |
| 9 | + config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/shakapacker" |
18 | 10 |
|
19 |
| - # If you are using this in your spec_helper.rb (or rails_helper.rb): |
20 |
| - # |
21 |
| - # ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config) |
| 11 | + # This is the file used for server rendering of React when using `(prerender: true)` |
| 12 | + # If you are never using server rendering, you may set this to "". |
| 13 | + # If you are using the same file for client and server rendering, having this set probably does |
| 14 | + # not affect performance. |
| 15 | + config.server_bundle_js_file = "server-bundle.js" |
| 16 | + |
| 17 | + # React on Rails 16 compatibility: Workaround for removed error handling |
22 | 18 | #
|
23 |
| - # with rspec then this controls what npm command is run |
24 |
| - # to automatically refresh your webpack assets on every test run. |
| 19 | + # BREAKING CHANGE in v16: React on Rails 14.2.1 had robust error handling that would |
| 20 | + # fallback to the Shakapacker output path when bundle lookup failed. This was removed |
| 21 | + # in v16.0.1.rc.2, causing it to look in the wrong directory during tests. |
25 | 22 | #
|
26 |
| - # Alternately, you can remove the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets` |
27 |
| - # and set the config/shakapacker.yml option for test to true. |
28 |
| - config.build_test_command = "RAILS_ENV=test bin/shakapacker" |
| 23 | + # This configuration tells React on Rails where to find bundles in test environment. |
| 24 | + # Without this, it defaults to public/webpack/test/ instead of public/packs/ |
| 25 | + config.generated_assets_dir = Rails.public_path.join("packs").to_s if Rails.env.test? |
29 | 26 |
|
30 | 27 | ################################################################################
|
| 28 | + # CLIENT RENDERING OPTIONS |
| 29 | + # Below options can be overriden by passing options to the react_on_rails |
| 30 | + # `render_component` view helper method. |
| 31 | + ################################################################################ |
| 32 | + |
| 33 | + # Default is false. Can be overriden at the component level. |
| 34 | + # Set to false for debugging issues before turning on to true. |
| 35 | + config.prerender = true |
| 36 | + |
| 37 | + # default is true for development, off otherwise |
| 38 | + config.trace = Rails.env.development? |
| 39 | + |
31 | 40 | ################################################################################
|
32 | 41 | # SERVER RENDERING OPTIONS
|
| 42 | + # Applicable options can be overriden by passing options to the react_on_rails |
| 43 | + # `render_component` view helper method. |
33 | 44 | ################################################################################
|
34 |
| - # This is the file used for server rendering of React when using `(prerender: true)` |
35 |
| - # If you are never using server rendering, you should set this to "". |
36 |
| - # Note, there is only one server bundle, unlike JavaScript where you want to minimize the size |
37 |
| - # of the JS sent to the client. For the server rendering, React on Rails creates a pool of |
38 |
| - # JavaScript execution instances which should handle any component requested. |
39 |
| - # |
40 |
| - # While you may configure this to be the same as your client bundle file, this file is typically |
41 |
| - # different. You should have ONE server bundle which can create all of your server rendered |
42 |
| - # React components. |
43 |
| - # |
44 |
| - config.server_bundle_js_file = "server-bundle.js" |
45 | 45 |
|
46 |
| - # Configure where server bundles are output. Defaults to "ssr-generated". |
47 |
| - # This should match your webpack configuration for server bundles. |
48 |
| - config.server_bundle_output_path = "ssr-generated" |
| 46 | + # If set to true, this forces Rails to reload the server bundle if it is modified |
| 47 | + config.development_mode = Rails.env.development? |
| 48 | + |
| 49 | + # For server rendering. This can be set to false so that server side messages are discarded. |
| 50 | + # Default is true. Be cautious about turning this off. |
| 51 | + config.replay_console = true |
49 | 52 |
|
50 |
| - # Enforce that server bundles are only loaded from private (non-public) directories. |
51 |
| - # When true, server bundles will only be loaded from the configured server_bundle_output_path. |
52 |
| - # This is recommended for production to prevent server-side code from being exposed. |
53 |
| - config.enforce_private_server_bundles = true |
| 53 | + # Default is true. Logs server rendering messages to Rails.logger.info |
| 54 | + config.logging_on_server = true |
54 | 55 |
|
| 56 | + # Change to true to raise exception on server if the JS code throws. Let's do this only if not |
| 57 | + # in production, as the JS code might still work on the client and we don't want to blow up the |
| 58 | + # whole Rails page. |
| 59 | + config.raise_on_prerender_error = !Rails.env.production? |
| 60 | + |
| 61 | + # Server rendering only (not for render_component helper) |
| 62 | + # You can configure your pool of JS virtual machines and specify where it should load code: |
| 63 | + # On MRI, use `therubyracer` for the best performance |
| 64 | + # (see [discussion](https://github.com/reactjs/react-rails/pull/290)) |
| 65 | + # On MRI, you'll get a deadlock with `pool_size` > 1 |
| 66 | + # If you're using JRuby, you can increase `pool_size` to have real multi-threaded rendering. |
| 67 | + config.server_renderer_pool_size = 1 # increase if you're on JRuby |
| 68 | + config.server_renderer_timeout = 20 # seconds |
| 69 | + |
| 70 | + ################################################################################ |
| 71 | + # I18N OPTIONS |
55 | 72 | ################################################################################
|
| 73 | + # Replace the following line to the location where you keep translation.js & default.js. |
| 74 | + config.i18n_dir = Rails.root.join("client/app/libs/i18n") |
| 75 | + |
56 | 76 | ################################################################################
|
57 |
| - # FILE SYSTEM BASED COMPONENT REGISTRY |
| 77 | + # MISCELLANEOUS OPTIONS |
58 | 78 | ################################################################################
|
59 |
| - # `components_subdirectory` is the name of the matching directories that contain automatically registered components |
60 |
| - # for use in the Rails views. The default is nil, you can enable the feature by updating it in the next line. |
61 |
| - config.components_subdirectory = "ror_components" |
62 |
| - # |
63 |
| - # For automated component registry, `render_component` view helper method tries to load bundle for component from |
64 |
| - # generated directory. default is false, you can pass option at the time of individual usage or update the default |
65 |
| - # in the following line |
66 |
| - config.auto_load_bundle = true |
| 79 | + |
| 80 | + # This allows you to add additional values to the Rails Context. Implement one static method |
| 81 | + # called `custom_context(view_context)` and return a Hash. |
| 82 | + config.rendering_extension = nil |
| 83 | + config.i18n_output_format = "js" |
67 | 84 | end
|
0 commit comments