react_on_rails 13.4.0 → 14.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -2
  3. data/Gemfile.development_dependencies +10 -9
  4. data/Gemfile.lock +434 -0
  5. data/README.md +25 -17
  6. data/lib/generators/react_on_rails/base_generator.rb +3 -2
  7. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  8. data/lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml +1 -1
  9. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +2 -2
  10. data/lib/generators/react_on_rails/templates/dev_tests/spec/system/hello_world_spec.rb +1 -1
  11. data/lib/react_on_rails/configuration.rb +39 -25
  12. data/lib/react_on_rails/git_utils.rb +3 -3
  13. data/lib/react_on_rails/helper.rb +3 -4
  14. data/lib/react_on_rails/json_output.rb +0 -17
  15. data/lib/react_on_rails/locales/base.rb +4 -4
  16. data/lib/react_on_rails/locales/to_js.rb +1 -1
  17. data/lib/react_on_rails/packs_generator.rb +5 -6
  18. data/lib/react_on_rails/react_component/render_options.rb +1 -1
  19. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +9 -9
  20. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +3 -3
  21. data/lib/react_on_rails/test_helper.rb +2 -2
  22. data/lib/react_on_rails/utils.rb +2 -8
  23. data/lib/react_on_rails/version.rb +1 -1
  24. data/lib/react_on_rails/version_checker.rb +2 -2
  25. data/lib/react_on_rails/webpacker_utils.rb +6 -0
  26. data/lib/tasks/assets.rake +1 -1
  27. data/react_on_rails.gemspec +4 -4
  28. metadata +5 -132
  29. data/.bookignore +0 -15
  30. data/.circleci/config.yml +0 -338
  31. data/.coveralls.yml +0 -1
  32. data/.dockerignore +0 -2
  33. data/.eslintignore +0 -17
  34. data/.eslintrc +0 -53
  35. data/.github/FUNDING.yml +0 -1
  36. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -23
  37. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  38. data/.github/PULL_REQUEST_TEMPLATE.md +0 -19
  39. data/.github/workflows/lint-js-and-ruby.yml +0 -54
  40. data/.github/workflows/main.yml +0 -183
  41. data/.github/workflows/package-js-tests.yml +0 -35
  42. data/.github/workflows/rspec-package-specs.yml +0 -46
  43. data/.gitignore +0 -33
  44. data/.npmignore +0 -22
  45. data/.prettierignore +0 -14
  46. data/.prettierrc +0 -20
  47. data/.rspec +0 -2
  48. data/.rubocop.yml +0 -134
  49. data/.scss-lint.yml +0 -205
  50. data/.travis.yml +0 -61
  51. data/book.json +0 -18
  52. data/docs/additional-details/generator-details.md +0 -56
  53. data/docs/additional-details/manual-installation-overview.md +0 -30
  54. data/docs/additional-details/migrating-from-react-rails.md +0 -17
  55. data/docs/additional-details/recommended-project-structure.md +0 -69
  56. data/docs/additional-details/tips-for-usage-with-sp6.md +0 -15
  57. data/docs/additional-details/updating-dependencies.md +0 -31
  58. data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +0 -10
  59. data/docs/api/javascript-api.md +0 -99
  60. data/docs/api/redux-store-api.md +0 -102
  61. data/docs/api/view-helpers-api.md +0 -133
  62. data/docs/contributor-info/errors-with-hooks.md +0 -45
  63. data/docs/contributor-info/generator-testing.md +0 -11
  64. data/docs/contributor-info/linters.md +0 -68
  65. data/docs/contributor-info/pull-requests.md +0 -42
  66. data/docs/contributor-info/releasing.md +0 -76
  67. data/docs/deployment/elastic-beanstalk.md +0 -63
  68. data/docs/deployment/heroku-deployment.md +0 -39
  69. data/docs/getting-started.md +0 -196
  70. data/docs/guides/client-vs-server-rendering.md +0 -27
  71. data/docs/guides/configuration.md +0 -289
  72. data/docs/guides/deployment.md +0 -5
  73. data/docs/guides/file-system-based-automated-bundle-generation.md +0 -197
  74. data/docs/guides/hmr-and-hot-reloading-with-the-webpack-dev-server.md +0 -104
  75. data/docs/guides/how-react-on-rails-works.md +0 -44
  76. data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +0 -40
  77. data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +0 -98
  78. data/docs/guides/i18n.md +0 -87
  79. data/docs/guides/installation-into-an-existing-rails-app.md +0 -66
  80. data/docs/guides/minitest-configuration.md +0 -31
  81. data/docs/guides/rails-webpacker-react-integration-options.md +0 -213
  82. data/docs/guides/react-on-rails-overview.md +0 -29
  83. data/docs/guides/react-server-rendering.md +0 -32
  84. data/docs/guides/render-functions-and-railscontext.md +0 -205
  85. data/docs/guides/rspec-configuration.md +0 -73
  86. data/docs/guides/tutorial.md +0 -371
  87. data/docs/guides/upgrading-react-on-rails.md +0 -304
  88. data/docs/guides/webpack-configuration.md +0 -42
  89. data/docs/home.md +0 -23
  90. data/docs/javascript/angular-js-integration-migration.md +0 -28
  91. data/docs/javascript/asset-pipeline.md +0 -12
  92. data/docs/javascript/capistrano-deployment.md +0 -18
  93. data/docs/javascript/code-splitting.md +0 -165
  94. data/docs/javascript/converting-from-custom-webpack-config-to-rails-webpacker-config.md +0 -10
  95. data/docs/javascript/credits.md +0 -10
  96. data/docs/javascript/foreman-issues.md +0 -15
  97. data/docs/javascript/images.md +0 -57
  98. data/docs/javascript/node-dependencies-and-npm.md +0 -19
  99. data/docs/javascript/react-and-redux.md +0 -36
  100. data/docs/javascript/react-helmet.md +0 -100
  101. data/docs/javascript/react-router.md +0 -90
  102. data/docs/javascript/server-rendering-tips.md +0 -55
  103. data/docs/javascript/troubleshooting-when-using-shakapacker.md +0 -77
  104. data/docs/javascript/troubleshooting-when-using-webpacker.md +0 -90
  105. data/docs/javascript/webpack-v1-notes.md +0 -23
  106. data/docs/javascript/webpack.md +0 -22
  107. data/docs/misc/articles.md +0 -20
  108. data/docs/misc/code_of_conduct.md +0 -13
  109. data/docs/misc/doctrine.md +0 -77
  110. data/docs/misc/style.md +0 -33
  111. data/docs/misc/tips.md +0 -10
  112. data/docs/outdated/deferred-rendering.md +0 -39
  113. data/docs/outdated/rails-assets-relative-paths.md +0 -195
  114. data/docs/outdated/rails-assets.md +0 -77
  115. data/docs/outdated/rails3.md +0 -9
  116. data/docs/rails/convert-rails-5-api-only-app.md +0 -19
  117. data/docs/rails/rails-engine-integration.md +0 -32
  118. data/docs/rails/rails_view_rendering_from_inline_javascript.md +0 -36
  119. data/docs/rails/turbolinks.md +0 -124
  120. data/docs/react-on-rails-pro/react-on-rails-pro.md +0 -43
  121. data/docs/testimonials/hvmn.md +0 -25
  122. data/docs/testimonials/resortpass.md +0 -13
  123. data/docs/testimonials/testimonials.md +0 -28
  124. data/jest.config.js +0 -4
  125. data/package-scripts.yml +0 -49
  126. data/package.json +0 -96
  127. data/rakelib/docker.rake +0 -26
  128. data/rakelib/dummy_apps.rake +0 -30
  129. data/rakelib/example_type.rb +0 -96
  130. data/rakelib/examples.rake +0 -64
  131. data/rakelib/examples_config.yml +0 -14
  132. data/rakelib/lint.rake +0 -30
  133. data/rakelib/node_package.rake +0 -15
  134. data/rakelib/release.rake +0 -92
  135. data/rakelib/run_rspec.rake +0 -103
  136. data/rakelib/task_helpers.rb +0 -62
  137. data/script/bootstrap +0 -33
  138. data/script/release +0 -3
  139. data/script/setup +0 -23
  140. data/script/test +0 -38
  141. data/webpackConfigLoader.js +0 -71
  142. data/yarn.lock +0 -7010
@@ -1,196 +0,0 @@
1
- # Getting Started
2
-
3
- Note, the best way to understand how to use ReactOnRails is to study a few simple examples. You can do a quick demo setup, either on your existing app or on a new Rails app.
4
-
5
- This documentation assumes the usage of ReactOnRails with Shakapacker 7. For installation on Shakapacker 6, check [tips for usage with Shakapacker 6](https://www.shakacode.com/react-on-rails/docs/aditional-details/tips-for-usage-with-sp6) first.
6
-
7
- 1. Do the quick [tutorial](https://www.shakacode.com/react-on-rails/docs/guides/tutorial/).
8
- 2. Add React on Rails to an existing Rails app per [the instructions](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/).
9
- 3. Look at [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy), a simple, no DB example.
10
- 3. Look at [github.com/shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial); it's a full-featured example live at [www.reactrails.com](http://reactrails.com).
11
-
12
- ## Basic Installation
13
-
14
- You need a Rails application with Shakapacker installed and configured on it. Check [Shakapacker documentation](https://github.com/shakacode/shakapacker) for more details but typically you need the following steps:
15
-
16
- ```bash
17
- rails new PROJECT_NAME --skip-javascript
18
- cd PROJECT_NAME
19
- bundle add shakapacker --strict
20
- rails shakapacker:install
21
- ```
22
-
23
- You may need to check [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/) if you have an already working Rails application.
24
-
25
- 1. Add the `react_on_rails` gem to Gemfile:
26
-
27
- ```bash
28
- bundle add react_on_rails --strict
29
- ```
30
-
31
- Commit this to git (or else you cannot run the generator in the next step unless you pass the option `--ignore-warnings`).
32
-
33
- 2. Run the install generator:
34
-
35
- ```bash
36
- rails generate react_on_rails:install
37
- ```
38
-
39
- 3. Start the app:
40
-
41
- - Run `./bin/dev` for HMR
42
- - Run `./bin/dev-static` for statically created bundles (no HMR)
43
-
44
- 4. Visit http://localhost:3000/hello_world.
45
-
46
-
47
- ### Turning on server rendering
48
-
49
- With the code from running the React on Rails generator above:
50
-
51
- 1. Edit `app/views/hello_world/index.html.erb` and set the `prerender` option to `true`.
52
-
53
- You may need to use `Node` as your js runtime environment by setting `EXECJS_RUNTIME=Node` into your environment variables.
54
-
55
- 2. Refresh the page.
56
-
57
- Below is the line where you turn server rendering on by setting `prerender` to true:
58
-
59
- ```erb
60
- <%= react_component("HelloWorld", props: @hello_world_props, prerender: true) %>
61
- ```
62
-
63
- Note, if you got an error in your console regarding "ReferenceError: window is not defined",
64
- then you need to edit `config/shakapacker.yml` and set `hmr: false` and `inline: false`.
65
- See [rails/webpacker PR 2644](https://github.com/rails/webpacker/pull/2644) for a fix for this
66
- issue.
67
-
68
- ## Basic Usage
69
-
70
- ### Configuration
71
-
72
- * Configure `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [docs/basics/configuration.md](https://www.shakacode.com/react-on-rails/docs/guides/configuration/) for documentation of all configuration options.
73
- * Configure `config/shakapacker.yml`. If you used the generator and the default Shakapacker setup, you don't need to touch this file. If you are customizing your setup, then consult the [spec/dummy/config/shakapacker.yml](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/shakapacker.yml) example or the official default [shakapacker.yml](https://github.com/shakacode/shakapacker/blob/master/lib/install/config/shakapacker.yml).
74
- * Most apps should rely on the Shakapacker setup for Webpack. Shakapacker v6+ includes support for webpack version 5.
75
-
76
- ## Including your React Component on your Rails Views
77
-
78
- - React components are rendered via your Rails Views. Here's an ERB sample:
79
-
80
- ```erb
81
- <%= react_component("HelloWorld", props: @some_props) %>
82
- ```
83
-
84
- - **Server-Side Rendering**: Your React component is first rendered into HTML on the server. Use the **prerender** option:
85
-
86
- ```erb
87
- <%= react_component("HelloWorld", props: @some_props, prerender: true) %>
88
- ```
89
-
90
- - The `component_name` parameter is a string matching the name you used to expose your React component globally. So, in the above examples, if you had a React component named "HelloWorld", you would register it with the following lines:
91
-
92
- ```js
93
- import ReactOnRails from 'react-on-rails';
94
- import HelloWorld from './HelloWorld';
95
- ReactOnRails.register({ HelloWorld });
96
- ```
97
-
98
- Exposing your component in this way is how React on Rails is able to reference your component from a Rails view. You can expose as many components as you like, as long as their names do not collide. See below for the details of how you expose your components via the react_on_rails webpack configuration. You may call `ReactOnRails.register` many times.
99
-
100
- - `@some_props` can be either a hash or JSON string. This is an optional argument assuming you do not need to pass any options (if you want to pass options, such as `prerender: true`, but you do not want to pass any properties, simply pass an empty hash `{}`). This will make the data available in your component:
101
-
102
- ```ruby
103
- # Rails View
104
- <%= react_component("HelloWorld", props: { name: "Stranger" }) %>
105
- ```
106
-
107
- - This is what your HelloWorld.js file might contain. The railsContext is always available for any parameters that you _always_ want available for your React components. It has _nothing_ to do with the concept of the [React Context](https://reactjs.org/docs/context.html). See [Render-Functions and the RailsContext](https://www.shakacode.com/react-on-rails/docs/guides/render-functions-and-railscontext/) for more details on this topic.
108
-
109
- ```js
110
- import React from 'react';
111
-
112
- export default (props, railsContext) => {
113
- // Note wrap in a function to make this a React function component
114
- return () => (
115
- <div>
116
- Your locale is {railsContext.i18nLocale}.<br/>
117
- Hello, {props.name}!
118
- </div>
119
- );
120
- };
121
- ```
122
-
123
- See the [View Helpers API](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/) for more details on `react_component` and its sibling function `react_component_hash`.
124
-
125
- ## Globally Exposing Your React Components
126
-
127
- For the React on Rails view helper `react_component` to use your React components, you will have to **register** them in your JavaScript code.
128
-
129
- Use modules just as you would when using Webpack and React without Rails. The difference is that instead of mounting React components directly to an element using `React.render`, you **register your components to ReactOnRails and then mount them with helpers inside of your Rails views**.
130
-
131
- This is how to expose a component to the `react_component` view helper.
132
-
133
- ```javascript
134
- // app/javascript/packs/hello-world-bundle.js
135
- import HelloWorld from '../components/HelloWorld';
136
- import ReactOnRails from 'react-on-rails';
137
- ReactOnRails.register({ HelloWorld });
138
- ```
139
-
140
- #### Different Server-Side Rendering Code (and a Server-Specific Bundle)
141
-
142
- You may want different code for your server-rendered components running server side versus client side. For example, if you have an animation that runs when a component is displayed, you might need to turn that off when server rendering. One way to handle this is conditional code like `if (window) { doClientOnlyCode() }`.
143
-
144
- Another way is to use a separate webpack configuration file that can use a different server side entry file, like 'serverRegistration.js' as opposed to 'clientRegistration.js.' That would set up different code for server rendering.
145
-
146
- For details on techniques to use different code for client and server rendering, see: [How to use different versions of a file for client and server rendering](https://forum.shakacode.com/t/how-to-use-different-versions-of-a-file-for-client-and-server-rendering/1352). (_Requires creating a free account._)
147
-
148
- ## Specifying Your React Components: Register directly or use render-functions
149
-
150
- You have two ways to specify your React components. You can either register the React component (either function or class component) directly, or you can create a function that returns a React component, which we using the name of a "render-function". Creating a render-function allows you to:
151
-
152
- 1. Access to the `railsContext`. See the [documentation for the railsContext](https://www.shakacode.com/react-on-rails/docs/guides/render-functions-and-railscontext/) in terms of why you might need it. You **need** a Render-Function to access the `railsContext`.
153
- 2. Use the passed-in props to initialize a redux store or set up `react-router`.
154
- 3. Return different components depending on what's in the props.
155
-
156
- Note, the return value of a **Render-Function** should be either a React Function or Class Component or an object representing server rendering results.
157
-
158
- **Do not return a React Element (JSX).**
159
-
160
- ReactOnRails will automatically detect a registered Render-Function by the fact that the function takes
161
- more than 1 parameter. In other words, if you want the ability to provide a function that returns the
162
- React component, then you need to specify at least a second parameter. This is the `railsContext`.
163
- If you're not using this parameter, declare your function with the unused param:
164
-
165
- ```js
166
- const MyComponentGenerator = (props, _railsContext) => {
167
- if (props.print) {
168
- // This is a React FunctionComponent because it is wrapped in a function.
169
- return () => <H1>{JSON.stringify(props)}</H1>;
170
- }
171
- }
172
- ```
173
-
174
- Thus, there is no difference between registering a React Function Component or class Component versus a "Render-Function." Just call `ReactOnRails.register`.
175
-
176
- ## react_component_hash for Render-Functions
177
-
178
- Another reason to use a Render-Function is that sometimes in server rendering, specifically with React Router, you need to return the result of calling ReactDOMServer.renderToString(element). You can do this by returning an object with the following shape: `{ renderedHtml, redirectLocation, error }`. Make sure you use this function with `react_component_hash`.
179
-
180
- For server rendering, if you wish to return multiple HTML strings from a Render-Function, you may return an Object from your Render-Function with a single top-level property of `renderedHtml`. Inside this Object, place a key called `componentHtml`, along with any other needed keys. An example scenario of this is when you are using side effects libraries like [React Helmet](https://github.com/nfl/react-helmet). Your Ruby code will get this Object as a Hash containing keys `componentHtml` and any other custom keys that you added:
181
-
182
- ```js
183
- { renderedHtml: { componentHtml, customKey1, customKey2} }
184
- ```
185
-
186
- For details on using react_component_hash with react-helmet, see [our react-helmet documentation](https://www.shakacode.com/react-on-rails/docs/additional-reading/react-helmet/).
187
-
188
- ## Error Handling
189
-
190
- * All errors from ReactOnRails will be of type ReactOnRails::Error.
191
- * Prerendering (server rendering) errors get context information for HoneyBadger and Sentry for easier debugging.
192
-
193
- ## I18n
194
-
195
- React on Rails provides an option for automatic conversions of Rails `*.yml` locale files into `*.json` or `*.js*.
196
- See the [How to add I18n](https://www.shakacode.com/react-on-rails/docs/guides/i18n/) for a summary of adding I18n.
@@ -1,27 +0,0 @@
1
- # Client-Side Rendering vs. Server-Side Rendering
2
-
3
- *Also, see [our react server-rendering documentation](https://www.shakacode.com/react-on-rails/docs/guides/react-server-rendering/).*
4
-
5
- In most cases, you should use the `prerender: false` (default behavior) with the provided 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`.
6
-
7
- 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. By default, ExecJS uses the Node.js runtime. You can use alternative runtimes as outlined in [ExecJS readme](https://github.com/rails/execjs/blob/master/README.md).
8
-
9
- Note: if you use the [mini_racer](https://github.com/rubyjs/mini_racer) runtime and run into a `ReferenceError: TextEncoder is not defined` error, see [this comment](https://github.com/shakacode/react_on_rails/issues/1457#issuecomment-1165026717) for a solution.
10
-
11
- 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).
12
-
13
- 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:
14
-
15
- 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.
16
- 2. 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.
17
- 3. 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.
18
-
19
- **Note**: 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.
20
-
21
- # Different Server-Side Rendering Code (and a Server-Specific Bundle)
22
-
23
- You may want different code for your server-rendered components running server side versus client side. For example, if you have an animation that runs when a component is displayed, you might need to turn that off when server rendering. One way to handle this is conditional code like `if (window) { doClientOnlyCode() }`.
24
-
25
- Another way is to use a separate webpack configuration file that can use a different server side entry file, like 'serverRegistration.js' as opposed to 'clientRegistration.js.' That would set up different code for server rendering.
26
-
27
- For details on techniques to use different code for client and server rendering, see: [How to use different versions of a file for client and server rendering](https://forum.shakacode.com/t/how-to-use-different-versions-of-a-file-for-client-and-server-rendering/1352). _Requires creating a free account._
@@ -1,289 +0,0 @@
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
- ```
@@ -1,5 +0,0 @@
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.