react_on_rails 11.1.4 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +320 -0
- data/.eslintignore +2 -1
- data/.eslintrc +30 -2
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +3 -1
- data/.prettierignore +10 -0
- data/.prettierrc +23 -0
- data/.release-it.json +3 -0
- data/.rubocop.yml +37 -11
- data/.travis.yml +10 -20
- data/CHANGELOG.md +126 -4
- data/CONTRIBUTING.md +61 -80
- data/Gemfile +3 -5
- data/KUDOS.md +4 -1
- data/REACT-ON-RAILS-PRO-LICENSE +95 -0
- data/README.md +148 -89
- data/Rakefile +0 -7
- data/SUMMARY.md +12 -12
- data/book.json +5 -5
- data/docs/additional-reading/asset-pipeline.md +8 -16
- data/docs/additional-reading/images.md +1 -1
- data/docs/additional-reading/rails_view_rendering_from_inline_javascript.md +2 -1
- data/docs/additional-reading/react-helmet.md +30 -10
- data/docs/additional-reading/react-router.md +52 -75
- data/docs/additional-reading/server-rendering-tips.md +12 -7
- data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +10 -0
- data/docs/api/javascript-api.md +3 -3
- data/docs/api/redux-store-api.md +4 -2
- data/docs/api/view-helpers-api.md +17 -14
- data/docs/basics/client-vs-server-rendering.md +8 -2
- data/docs/basics/configuration.md +87 -73
- data/docs/basics/deployment.md +2 -4
- data/docs/basics/generator-details.md +1 -1
- data/docs/basics/heroku-deployment.md +24 -0
- data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +49 -0
- data/docs/basics/i18n.md +45 -23
- data/docs/basics/installation-into-an-existing-rails-app.md +4 -9
- data/docs/basics/minitest-configuration.md +31 -0
- data/docs/basics/react-server-rendering.md +3 -1
- data/docs/basics/recommended-project-structure.md +21 -15
- data/docs/basics/{generator-functions-and-railscontext.md → render-functions-and-railscontext.md} +59 -21
- data/docs/basics/rspec-configuration.md +29 -18
- data/docs/basics/upgrading-react-on-rails.md +74 -3
- data/docs/basics/webpack-configuration.md +29 -8
- data/docs/contributor-info/errors-with-hooks.md +45 -0
- data/docs/contributor-info/pull-requests.md +44 -0
- data/docs/misc/doctrine.md +1 -1
- data/docs/{misc-pending → outdated}/code-splitting.md +13 -9
- data/docs/{basics → outdated}/how-react-on-rails-works.md +8 -4
- data/docs/{misc-pending → outdated}/manual-installation-overview.md +5 -5
- data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +3 -3
- data/docs/{misc-pending → outdated}/rails-assets.md +2 -12
- data/docs/testimonials/hvmn.md +25 -0
- data/docs/testimonials/resortpass.md +13 -0
- data/docs/testimonials/testimonials.md +28 -0
- data/docs/tutorial.md +182 -44
- data/jest.config.js +4 -0
- data/lib/generators/react_on_rails/base_generator.rb +2 -2
- data/lib/generators/react_on_rails/dev_tests_generator.rb +2 -1
- data/lib/generators/react_on_rails/generator_helper.rb +4 -6
- data/lib/generators/react_on_rails/install_generator.rb +2 -0
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +3 -1
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +26 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +20 -40
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +4 -1
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +4 -8
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
- data/lib/react_on_rails/configuration.rb +60 -29
- data/lib/react_on_rails/error.rb +2 -0
- data/lib/react_on_rails/git_utils.rb +2 -0
- data/lib/react_on_rails/helper.rb +110 -159
- data/lib/react_on_rails/json_output.rb +1 -1
- data/lib/react_on_rails/json_parse_error.rb +2 -0
- data/lib/react_on_rails/locales/base.rb +150 -0
- data/lib/react_on_rails/locales/to_js.rb +37 -0
- data/lib/react_on_rails/locales/to_json.rb +27 -0
- data/lib/react_on_rails/prerender_error.rb +11 -15
- data/lib/react_on_rails/react_component/render_options.rb +4 -0
- data/lib/react_on_rails/server_rendering_js_code.rb +42 -0
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +85 -60
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +7 -8
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +17 -0
- data/lib/react_on_rails/utils.rb +19 -20
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/version_checker.rb +5 -1
- data/lib/react_on_rails/webpacker_utils.rb +27 -2
- data/lib/react_on_rails.rb +4 -1
- data/lib/tasks/assets.rake +33 -46
- data/lib/tasks/locale.rake +4 -2
- data/package-scripts.yml +49 -0
- data/package.json +41 -31
- data/rakelib/dummy_apps.rake +1 -9
- data/rakelib/example_type.rb +3 -1
- data/rakelib/examples.rake +3 -0
- data/rakelib/lint.rake +2 -7
- data/rakelib/node_package.rake +2 -2
- data/rakelib/release.rake +3 -8
- data/rakelib/run_rspec.rake +5 -18
- data/react_on_rails.gemspec +4 -5
- data/tsconfig.json +14 -0
- data/webpackConfigLoader.js +5 -4
- data/yarn.lock +7177 -2311
- metadata +54 -55
- data/Gemfile.rails32 +0 -74
- data/docs/additional-reading/babel.md +0 -5
- data/docs/additional-reading/heroku-deployment.md +0 -92
- data/docs/additional-reading/hot-reloading-rails-development.md +0 -57
- data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
- data/docs/testimonials.md +0 -11
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
- data/lib/react_on_rails/assets_precompile.rb +0 -150
- data/lib/react_on_rails/locales_to_js.rb +0 -134
- /data/docs/{misc → outdated}/rails3.md +0 -0
data/docs/basics/{generator-functions-and-railscontext.md → render-functions-and-railscontext.md}
RENAMED
|
@@ -1,45 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Render-Functions and the Rails Context
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Render-Functions
|
|
4
4
|
|
|
5
|
-
When you use a
|
|
5
|
+
When you use a render-function to create react components (or renderedHtml on the server), or you
|
|
6
|
+
used shared redux stores, you get two params passed to your function that creates a React component:
|
|
6
7
|
|
|
7
8
|
1. `props`: Props that you pass in the view helper of either `react_component` or `redux_store`
|
|
8
|
-
2. `railsContext`: Rails contextual information, such as the current pathname. You can customize
|
|
9
|
+
2. `railsContext`: Rails contextual information, such as the current pathname. You can customize
|
|
10
|
+
this in your config file. **Note**: The `railsContext` is not related to the concept of a
|
|
11
|
+
["context" for React components](https://facebook.github.io/react/docs/context.html#how-to-use-context).
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
These parameters (`props` and `railsContext`) will be the same regardless of either client or server
|
|
14
|
+
side rendering, except for the key `serverSide` based on whether or not you are server rendering.
|
|
11
15
|
|
|
12
|
-
While you could manually configure your Rails code to pass the "`railsContext` information" with
|
|
16
|
+
While you could manually configure your Rails code to pass the "`railsContext` information" with
|
|
17
|
+
the rest of your "props", the `railsContext` is a convenience because it's passed consistently to
|
|
18
|
+
all invocations of render functions.
|
|
13
19
|
|
|
14
|
-
For example, suppose you create a "
|
|
20
|
+
For example, suppose you create a "render-function" called MyAppComponent.
|
|
15
21
|
|
|
16
22
|
```js
|
|
17
23
|
import React from 'react';
|
|
18
24
|
const MyAppComponent = (props, railsContext) => (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
// NOTE: need to wrap in a function so this is proper React function component that can use
|
|
26
|
+
// hooks
|
|
27
|
+
|
|
28
|
+
// the props get passed again, but we ignore since we use a closure
|
|
29
|
+
// or should we
|
|
30
|
+
() =>
|
|
31
|
+
<div>
|
|
32
|
+
<p>props are: {JSON.stringify(props)}</p>
|
|
33
|
+
<p>railsContext is: {JSON.stringify(railsContext)}
|
|
34
|
+
</p>
|
|
35
|
+
</div>
|
|
24
36
|
);
|
|
25
37
|
export default MyAppComponent;
|
|
26
38
|
```
|
|
27
39
|
|
|
40
|
+
------------------------------
|
|
41
|
+
|
|
42
|
+
_This would be alternate API where you have to call React.createElement and the React on Rails code doesn't do that._
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import React from 'react';
|
|
46
|
+
const MyAppComponent = (props, railsContext) => (
|
|
47
|
+
// NOTE: need to wrap in a function so this is proper React function component that can use
|
|
48
|
+
// hooks
|
|
49
|
+
React.createElement(
|
|
50
|
+
() =>
|
|
51
|
+
<div>
|
|
52
|
+
<p>props are: {JSON.stringify(props)}</p>
|
|
53
|
+
<p>railsContext is: {JSON.stringify(railsContext)}
|
|
54
|
+
</p>
|
|
55
|
+
</div>,
|
|
56
|
+
props)
|
|
57
|
+
);
|
|
58
|
+
export default MyAppComponent;
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
------------------------------------
|
|
62
|
+
|
|
28
63
|
*Note: you will get a React browser console warning if you try to serverRender this since the value of `serverSide` will be different for server rendering.*
|
|
29
64
|
|
|
30
|
-
So if you register your
|
|
65
|
+
So if you register your render-function `MyAppComponent`, it will get called like:
|
|
31
66
|
|
|
32
67
|
```js
|
|
33
68
|
reactComponent = MyAppComponent(props, railsContext);
|
|
34
69
|
```
|
|
35
70
|
|
|
36
|
-
and, similarly, any redux store always initialized with 2 parameters:
|
|
71
|
+
and, similarly, any redux store is always initialized with 2 parameters:
|
|
37
72
|
|
|
38
73
|
```js
|
|
39
74
|
reduxStore = MyReduxStore(props, railsContext);
|
|
40
75
|
```
|
|
41
76
|
|
|
42
|
-
Note: you never make these calls. React on Rails makes these calls when it does either client or server rendering. You will define functions that take these 2 params and return a React component or a Redux Store. Naturally, you do not have to use second parameter of the railsContext if you do not need it.
|
|
77
|
+
Note: you never make these calls. React on Rails makes these calls when it does either client or server rendering. You will define functions that take these 2 params and return a React component or a Redux Store. Naturally, you do not have to use second parameter of the railsContext if you do not need it. If you don't take a second parameter, then you're probably defining a React function component and you will simply return a React Element, often just JSX.
|
|
43
78
|
|
|
44
79
|
(Note: see below [section](#multiple-react-components-on-a-page-with-one-store) on how to setup redux stores that allow multiple components to talk to the same store.)
|
|
45
80
|
|
|
@@ -76,7 +111,7 @@ Plus, you can add your customizations to this. See "rendering extension" below.
|
|
|
76
111
|
|
|
77
112
|
## Rails Context
|
|
78
113
|
|
|
79
|
-
The `railsContext` is a second param passed to your
|
|
114
|
+
The `railsContext` is a second param passed to your render-functions for React components. This is in addition to the props that are passed from the `react_component` Rails helper. For example:
|
|
80
115
|
|
|
81
116
|
ERB view file:
|
|
82
117
|
|
|
@@ -91,7 +126,8 @@ This is what your HelloWorld.js file might contain. The railsContext is always a
|
|
|
91
126
|
import React from 'react';
|
|
92
127
|
|
|
93
128
|
export default (props, railsContext) => {
|
|
94
|
-
|
|
129
|
+
// Note, wrap in a function so this is React function component
|
|
130
|
+
return () => (
|
|
95
131
|
<div>
|
|
96
132
|
Your locale is {railsContext.i18nLocale}.<br/>
|
|
97
133
|
Hello, {props.name}!
|
|
@@ -100,15 +136,17 @@ export default (props, railsContext) => {
|
|
|
100
136
|
};
|
|
101
137
|
```
|
|
102
138
|
|
|
103
|
-
## Why is the railsContext
|
|
139
|
+
## Why is the railsContext only passed to render-functions?
|
|
104
140
|
|
|
105
|
-
There's no reason that the railsContext would ever get passed to your React component unless the value is explicitly put into the props used for rendering. If you create a react component, rather than a
|
|
141
|
+
There's no reason that the railsContext would ever get passed to your React component unless the value is explicitly put into the props used for rendering. If you create a react component, rather than a render-function, for use by React on Rails, then you get whatever props are passed in from the view helper, which **does not include the Rails Context**. It's trivial to wrap your component in a "render-function" to return a new component that takes both:
|
|
106
142
|
|
|
107
143
|
```js
|
|
108
144
|
import React from 'react';
|
|
109
145
|
import AppComponent from './AppComponent';
|
|
110
146
|
const AppComponentWithRailsContext = (props, railsContext) => (
|
|
111
|
-
|
|
147
|
+
// Create a React Function Component so you can
|
|
148
|
+
// use the React Hooks API in this React Function Component
|
|
149
|
+
() => <AppComponent {...{...props, railsContext}}/>
|
|
112
150
|
)
|
|
113
151
|
export default AppComponentWithRailsContext;
|
|
114
152
|
```
|
|
@@ -153,7 +191,7 @@ See [spec/dummy/config/initializers/react_on_rails.rb](https://github.com/shakac
|
|
|
153
191
|
module RenderingExtension
|
|
154
192
|
|
|
155
193
|
# Return a Hash that contains custom values from the view context that will get merged with
|
|
156
|
-
# the standard rails_context values and passed to all calls to
|
|
194
|
+
# the standard rails_context values and passed to all calls to render-functions used by the
|
|
157
195
|
# react_component and redux_store view helpers
|
|
158
196
|
def self.custom_context(view_context)
|
|
159
197
|
{
|
|
@@ -1,7 +1,31 @@
|
|
|
1
1
|
# RSpec Configuration
|
|
2
|
+
_Click [here for minitest](./minitest-configuration.md)_
|
|
3
|
+
|
|
4
|
+
# If your webpack configurations correspond to rails/webpacker's default setup
|
|
5
|
+
If you're able to configure your webpack configuration to be run by having your webpack configuration
|
|
6
|
+
returned by the files in `/config/webpack`, then you have 2 options to ensure that your files are
|
|
7
|
+
compiled by webpack before running tests and during production deployment:
|
|
8
|
+
|
|
9
|
+
1. **Use rails/webpacker's compile option**: Configure your `config/webpacker.yml` so that `compile: true` is for `test` and `production`
|
|
10
|
+
environments. Ensure that your `source_path` is correct, or else `rails/webpacker` won't correctly
|
|
11
|
+
detect changes.
|
|
12
|
+
2. **Use the react_on_rails settings and helpers**. Use the settings in `config/initializers/react_on_rails.rb`. Refer to [docs/configuration](./configuration.md).
|
|
13
|
+
|
|
14
|
+
```yml
|
|
15
|
+
config.build_test_command = "NODE_ENV=test RAILS_ENV=test bin/webpack"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Which should you use? If you're already using the `rails/webpacker` way to configure webpack, then
|
|
19
|
+
you can keep things simple and use the `rails/webpacker` options.
|
|
20
|
+
|
|
21
|
+
# Checking for stale assets using React on Rails
|
|
22
|
+
|
|
2
23
|
Because you will probably want to run RSpec tests that rely on compiled webpack assets (typically, your integration/feature specs where `js: true`), you will want to ensure you don't accidentally run tests on missing or stale webpack assets. If you did use stale Webpack assets, you will get invalid test results as your tests do not use the very latest JavaScript code.
|
|
3
24
|
|
|
4
|
-
|
|
25
|
+
As mentioned above, you can configure `compile: true` in `config/webpacker.yml` _if_ you've got configuration for
|
|
26
|
+
your webpack in the standard `rails/webpacker` spot of `config/webpack/<NODE_ENV>.js`
|
|
27
|
+
|
|
28
|
+
ReactOnRails also provides a helper method called `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`. Call this method from inside of the `RSpec.configure` block in your `spec/rails_helper.rb` file, passing the config as an argument. See file [lib/react_on_rails/test_helper.rb](../../lib/react_on_rails/test_helper.rb) for more details. You can customize this to your particular needs by replacing any of the default components used by `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`.
|
|
5
29
|
|
|
6
30
|
```ruby
|
|
7
31
|
RSpec.configure do |config|
|
|
@@ -20,42 +44,29 @@ If you are using Webpack to build CSS assets, you should do something like this
|
|
|
20
44
|
```
|
|
21
45
|
|
|
22
46
|
Please take note of the following:
|
|
23
|
-
- If you are using Webpacker, be **SURE** to configure the `source_path` in your `config/webpacker.yml` unless you are using the defaults for webpacker.
|
|
47
|
+
- If you are using Webpacker, be **SURE** to configure the `source_path` in your `config/webpacker.yml` unless you are using the defaults for webpacker.
|
|
24
48
|
|
|
25
49
|
- This utility uses your `build_test_command` to build the static generated files. This command **must not** include the `--watch` option. If you have different server and client bundle files, this command **must** create all the bundles. If you are using webpacker, the default value will come from the `config/webpacker.yml` value for the `public_output_path` and the `source_path`
|
|
26
50
|
|
|
27
|
-
- If you add an older file to your source files, that is already older than the produced output files, no new recompilation is done. The solution to this issue is to clear out your directory of webpack generated files when adding new source files that may have older dates.
|
|
51
|
+
- If you add an older file to your source files, that is already older than the produced output files, no new recompilation is done. The solution to this issue is to clear out your directory of webpack generated files when adding new source files that may have older dates.
|
|
28
52
|
|
|
29
|
-
- By default, the webpack processes look
|
|
53
|
+
- By default, the webpack processes look in the webpack generated files folder, configured via the `config/webpacker.yml` config values of `public_root_path` and `public_output_path`. If the webpack generated files folder is missing, is empty, or contains files in the `config.webpack_generated_files` list with `mtime`s older than any of the files in your `client` folder, the helper will recompile your assets.
|
|
30
54
|
|
|
31
55
|
The following `config/react_on_rails.rb` settings **must** match your setup:
|
|
32
56
|
```ruby
|
|
33
|
-
# Directory where your generated assets go. All generated assets must go to the same directory.
|
|
34
|
-
# Configure this in your webpack config files. This relative to your Rails root directory.
|
|
35
|
-
# We recommend having different generated assets dirs per Rails env.
|
|
36
|
-
config.generated_assets_dir = File.join(%w[public webpack], Rails.env)
|
|
37
|
-
|
|
38
57
|
# Define the files we need to check for webpack compilation when running tests.
|
|
39
|
-
# Generally, the manifest.json is good enough for this check if using webpacker
|
|
40
58
|
config.webpack_generated_files = %w( manifest.json )
|
|
41
59
|
|
|
42
60
|
# OR if you're not hashing the server-bundle.js, then you should include your server-bundle.js in the list.
|
|
43
61
|
# config.webpack_generated_files = %w( server-bundle.js manifest.json )
|
|
44
62
|
|
|
45
|
-
# OR if you're not using webpacker, your setup might look like.
|
|
46
|
-
# config.webpack_generated_files = %w( client-bundle.js server-bundle.js )
|
|
47
|
-
|
|
48
63
|
# If you are using the ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
|
49
64
|
# with rspec then this controls what yarn command is run
|
|
50
65
|
# to automatically refresh your webpack assets on every test run.
|
|
51
66
|
config.build_test_command = "yarn run build:test"
|
|
52
67
|
```
|
|
53
68
|
|
|
54
|
-
If you want to speed up the re-compiling process so you don't wait to run your tests to build the files, you can run your test compilation with the "watch" flags.
|
|
55
|
-
|
|
56
|
-
[spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy) contains examples of how to set the proc files for this purpose.
|
|
57
|
-
|
|
58
|
-
If you want to use a testing framework other than RSpec, please submit let us know on the changes you need to do and we'll update the docs.
|
|
69
|
+
If you want to speed up the re-compiling process so you don't wait to run your tests to build the files, you can run your test compilation with the "watch" flags. For example, `yarn run build:test --watch`
|
|
59
70
|
|
|
60
71
|

|
|
61
72
|
|
|
@@ -1,11 +1,82 @@
|
|
|
1
1
|
# Upgrading React on Rails
|
|
2
2
|
|
|
3
|
+
## Need Help Migrating?
|
|
4
|
+
If you would like help in migrating between React on Rails versions or help with implementing server rendering, please contact [justin@shakacode.com](mailto:justin@shakacode.com) for information about our [ShakaCode Pro Support](https://www.shakacode.com/work/shakacode-pro-support.pdf).
|
|
5
|
+
|
|
6
|
+
We specialize in helping companies to quickly and efficiently move from versions before 9 to current. The older versions use the Rails asset pipeline to package client assets. The current and recommended way is to use Webpack 4 for asset preparation. You may also need help migrating from the `rails/webpacker`'s Webpack configuration to a better setup ready for Server Side Rendering.
|
|
7
|
+
|
|
8
|
+
## Upgrading to v12
|
|
9
|
+
### Recent versions
|
|
10
|
+
Make sure that you are on a relatively more recent version of rails and webpacker.
|
|
11
|
+
v12 is tested on Rails 6. It should work on Rails v5. If you're on an older version,
|
|
12
|
+
and v12 doesn't work, please file an issue.
|
|
13
|
+
|
|
14
|
+
### i18n default format changed to JSON
|
|
15
|
+
* If you're using the internalization helper, then set `config.i18n_output_format = 'js'`. You can
|
|
16
|
+
later update to the default JSON format as you will need to update your usage of that file. A JSON
|
|
17
|
+
format is more efficient.
|
|
18
|
+
|
|
19
|
+
### Updated API for `ReactOnRails.register()`
|
|
20
|
+
|
|
21
|
+
In order to solve the issues regarding React Hooks compatibility, the number of parameters
|
|
22
|
+
for functions is used to determine if you have a render function that will get invoked to
|
|
23
|
+
return a React component, or you are registering a React component defined by a function.
|
|
24
|
+
|
|
25
|
+
##### Correct
|
|
26
|
+
|
|
27
|
+
Registered Objects are of the following types. Either of these will work:
|
|
28
|
+
1. Take **2 params** and return **a React function or class component**. A function component is a function
|
|
29
|
+
that takes zero or one params and returns a React Element, like JSX.
|
|
30
|
+
```js
|
|
31
|
+
export default (props, _railsContext) => () => <Component {...props} />;
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
2. Take only zero or one params and you return a React Element, often JSX.
|
|
35
|
+
```js
|
|
36
|
+
export default (props) => <Component {...props} />;
|
|
37
|
+
```
|
|
38
|
+
##### Broken, as this function takes two params and it returns a React Element from a JSX Literal
|
|
39
|
+
```js
|
|
40
|
+
export default (props, _railsContext) => <Component {...props} />;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
If you make this mistake, you'll get this warning
|
|
44
|
+
`Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: <Fragment />. Did you accidentally export a JSX literal instead of a component?`
|
|
45
|
+
|
|
46
|
+
And this error:
|
|
47
|
+
`react-dom.development.js:23965 Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.`
|
|
48
|
+
|
|
49
|
+
In this example, you need to wrap the `<Component {...props} />` in a function call like this which
|
|
50
|
+
results in the return value being a React function component.
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
export default (props, _railsContext) => () => <Component {...props} />;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
If you have a pure component, taking one or zero parameters, and you have an unnecessary function
|
|
57
|
+
wrapper such that you're returning a function rather than a React Element, then:
|
|
58
|
+
|
|
59
|
+
1. You won't see anything render.
|
|
60
|
+
2. You will see this warning in development mode: `Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.`
|
|
61
|
+
|
|
62
|
+
---------
|
|
63
|
+
|
|
64
|
+
## Upgrading rails/webpacker from v3 to v4
|
|
65
|
+
### Custom Webpack build file
|
|
66
|
+
The default value for `extract_css` is **false** in `config/webpack.yml`. Custom webpack builds should set this value to true or else no CSS link tags are generated. You have a custom webpack build if you are not using [rails/webpacker](https://github.com/rails/webpacker to setup your Webpack configuration.
|
|
67
|
+
|
|
68
|
+
```yml
|
|
69
|
+
default: &default
|
|
70
|
+
# other stuff
|
|
71
|
+
extract_css: true
|
|
72
|
+
# by default, extract and emit a css file. The default is false
|
|
73
|
+
```
|
|
74
|
+
|
|
3
75
|
## Upgrading to version 11
|
|
4
76
|
* Remove `server_render_method` from config/initializers/react_on_rails.rb. Alternate server rendering methods are part of React on Rails Pro. If you want to use a custom renderer, contact justin@shakacode.com. We have a custom node rendering solution in production for egghead.io.
|
|
5
77
|
* Remove your usage of ENV["TRACE_REACT_ON_RAILS"] usage. You can get all tracing with either specifying **`trace`** at your component or in your config/initializers/react_on_rails.rb file.
|
|
6
78
|
* ReactOnRails::Utils.server_bundle_file_name and ReactOnRails::Utils.bundle_file_name were removed. React on Rails Pro contains upgrades to enable component and other types caching with React on Rails.
|
|
7
79
|
|
|
8
|
-
|
|
9
80
|
## Upgrading to version 10
|
|
10
81
|
|
|
11
82
|
Pretty simple:
|
|
@@ -27,8 +98,8 @@ Reason for doing this: This enables your webpack bundles to bypass the Rails ass
|
|
|
27
98
|
##### ...while keeping your `client` directory
|
|
28
99
|
* `.gitignore`: add `/public/webpack/*`
|
|
29
100
|
* `Gemfile`: bump `react_on_rails` and add `webpacker`
|
|
30
|
-
* layout views: anything bundled by webpack will need to be requested by a `javascript_pack_tag` or `stylesheet_pack_tag`.
|
|
31
|
-
* Search your codebase for javascript_include_tag. Use the
|
|
101
|
+
* layout views: anything bundled by webpack will need to be requested by a `javascript_pack_tag` or `stylesheet_pack_tag`.
|
|
102
|
+
* Search your codebase for javascript_include_tag. Use the
|
|
32
103
|
* `config/initializers/assets.rb`: we no longer need to modify `Rails.application.config.assets.paths` or append anything to `Rails.application.config.assets.precompile`.
|
|
33
104
|
* `config/initializers/react_on_rails.rb`:
|
|
34
105
|
* Delete `config.generated_assets_dir`. Webpacker's config now supplies this information
|
|
@@ -1,18 +1,43 @@
|
|
|
1
1
|
# Webpack Configuration: custom setup for Webpack or rails/webpacker?
|
|
2
2
|
|
|
3
|
+
## Webpack vs. rails/webpacker
|
|
4
|
+
|
|
5
|
+
[Webpack](https://webpack.js.org) is the JavaScript npm package that prepares all your client-side assets. The Rails asset pipeline used to be the preferable way to prepare client-side assets.
|
|
6
|
+
|
|
7
|
+
[rails/webpacker](https://github.com/rails/webpacker) is the Ruby gem that mainly gives us 2 things:
|
|
8
|
+
|
|
9
|
+
1. View helpers for placing the Webpack bundles on your Rails views. React on Rails depends on these view helpers.
|
|
10
|
+
2. A layer of abstraction on top of Webpack customization. This is great for demo projects, but most real world projects will want a customized version of Webpack.
|
|
11
|
+
|
|
12
|
+
# React on Rails
|
|
13
|
+
|
|
3
14
|
Version 9 of React on Rails added support for the rails/webpacker view helpers so that Webpack produced assets would no longer pass through the Rails asset pipeline. As part of this change, React on Rails added a configuration option to support customization of the node_modules directory. This allowed React on Rails to support the rails/webpacker configuration of the Webpack configuration.
|
|
4
15
|
|
|
5
16
|
A key decision in your use React on Rails is whether you go with the rails/webpacker default setup or the traditional React on Rails setup of putting all your client side files under the `/client` directory. While there are technically 2 independent choices involved, the directory structure and the mechanism of Webpack configuration, for simplicity sake we'll assume that these choices go together.
|
|
6
17
|
|
|
7
18
|
## Option 1: Recommended: Traditional React on Rails using the /client directory
|
|
8
19
|
|
|
9
|
-
Until version 9, all React on Rails apps used the `/client` directory for configuring React on Rails in terms of the configuration of Webpack and location of your JavaScript and Webpack files, including the node_modules directory. Version 9 changed the default to `/` for the `node_modules` location using this value in `config/initializers/react_on_rails.rb`: `config.node_modules_location`.
|
|
20
|
+
Until version 9, all React on Rails apps used the `/client` directory for configuring React on Rails in terms of the configuration of Webpack and location of your JavaScript and Webpack files, including the node_modules directory. Version 9 changed the default to `/` for the `node_modules` location using this value in `config/initializers/react_on_rails.rb`: `config.node_modules_location`.
|
|
21
|
+
|
|
22
|
+
The [ShakaCode Team](http://www.shakacode.com) _recommends_ this approach for projects beyond the simplest cases as it provides the greatest transparency in your webpack and overall client-side setup. The *big advantage* to this is that almost everything within the `/client` directory will apply if you wish to convert your client-side code to a pure Single Page Application that runs without Rails. This allows you to Google for how to do something with Webpack configuration and what applies to a non-Rails app will apply just as well to a React on Rails app.
|
|
10
23
|
|
|
11
|
-
|
|
24
|
+
An examples of this pattern is the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial).
|
|
12
25
|
|
|
13
|
-
|
|
26
|
+
In this case, you don't need to understand the nuances of customization of your Webpack config via the [Webpacker mechanism](./docs/additional-reading/webpack-tips.md).
|
|
14
27
|
|
|
15
|
-
|
|
28
|
+
You can access values in the `config/webpacker.yml`
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
const { config, devServer } = require('@rails/webpacker');
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
You will want consider using some of the same values set in these files:
|
|
35
|
+
|
|
36
|
+
* https://github.com/rails/webpacker/blob/master/package/environments/base.js
|
|
37
|
+
* https://github.com/rails/webpacker/blob/master/package/environments/development.js
|
|
38
|
+
|
|
39
|
+
**Note**, if your node_modules directory is not at the top level of the Rails project, then you will need to set the
|
|
40
|
+
ENV value of WEBPACKER_CONFIG to the location of the `config/webpacker.yml` file per [rails/webpacker PR 2561](https://github.com/rails/webpacker/pull/2561).
|
|
16
41
|
|
|
17
42
|
## Option 2: Default Generator Setup: rails/webpacker app/javascript
|
|
18
43
|
|
|
@@ -20,10 +45,6 @@ Typical rails/webpacker apps have a standard directory structure as documented [
|
|
|
20
45
|
|
|
21
46
|
The *advantage* of using rails/webpacker to configure Webpack is that there is very little code needed to get started and you don't need to understand really anything about Webpack customization. The *big disadvantage* to this is that you will need to learn the ins and outs of the [rails/webpacker way to customize Webpack](https://github.com/rails/webpacker/blob/master/docs/webpack.md) which differs from the plain [Webpack way](https://webpack.js.org/).
|
|
22
47
|
|
|
23
|
-
Overall, consider carefully if you prefer the `rails/webpacker` directory structure and Webpack configuration, over the placement of all client side files within the `/client` directory along with conventional Webpack configuration. Once again, the `/client` directory setup is recommended.
|
|
24
|
-
|
|
25
48
|
You can find more details on this topic in [Recommended Project Structure](./recommended-project-structure.md).
|
|
26
49
|
|
|
27
50
|
See [Issue 982: Tutorial Generating Correct Project Structure?](https://github.com/shakacode/react_on_rails/issues/982) to discuss this issue.
|
|
28
|
-
|
|
29
|
-
For more details on project setup, see [Recommended Project Structure](./docs/basics/recommended-project-structure.md).
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Invalid hook call error
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
react.development.js:1465 Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
|
|
5
|
+
1. You might have mismatching versions of React and the renderer (such as React DOM)
|
|
6
|
+
2. You might be breaking the Rules of Hooks
|
|
7
|
+
3. You might have more than one copy of React in the same app
|
|
8
|
+
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The main reason to get this is due to multiple versions of React installed.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
cd <top level>
|
|
15
|
+
npm ls react
|
|
16
|
+
|
|
17
|
+
cd spec/dummy
|
|
18
|
+
npm ls react
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For the second one, you might get:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
react_on_rails@ /Users/justin/shakacode/react-on-rails/react_on_rails/spec/dummy
|
|
25
|
+
├── react@16.13.1
|
|
26
|
+
└─┬ react-on-rails@12.0.0 -> /Users/justin/shakacode/react-on-rails/react_on_rails invalid
|
|
27
|
+
└── react@16.13.1 extraneous
|
|
28
|
+
|
|
29
|
+
npm ERR! invalid: react-on-rails@12.0.0 /Users/justin/shakacode/react-on-rails/react_on_rails/spec/dummy/node_modules/react-on-rails
|
|
30
|
+
npm ERR! extraneous: react@16.13.1 /Users/justin/shakacode/react-on-rails/react_on_rails/spec/dummy/node_modules/react-on-rails/node_modules/react
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Make sure there is only one version of React installed!
|
|
34
|
+
|
|
35
|
+
If you used yarn link, then you'll have two versions of React installed.
|
|
36
|
+
|
|
37
|
+
Instead use [Yalc](https://github.com/whitecolor/yalc).
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
cd <top level>
|
|
41
|
+
yalc publish
|
|
42
|
+
|
|
43
|
+
cd spec/dummy
|
|
44
|
+
yalc link react-on-rails
|
|
45
|
+
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Pull Requests
|
|
2
|
+
|
|
3
|
+
## Checklist before Committing
|
|
4
|
+
1. `rake`: runs all linters and specs (you need Docker setup, see below)
|
|
5
|
+
2. Did you need any more tests for your change?
|
|
6
|
+
3. Did you document your change? Update the README.md?
|
|
7
|
+
4. Did you add a CHANGELOG.md entry?
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
For non-doc fixes:
|
|
11
|
+
|
|
12
|
+
* Provide changelog entry in the [unreleased section of the CHANGELOG.md](https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md#unreleased).
|
|
13
|
+
* Ensure CI passes and that you added a test that passes with the fix and fails without the fix.
|
|
14
|
+
* Squash all commits down to one with a nice commit message *ONLY* once final review is given. Make sure this single commit is rebased on top of master.
|
|
15
|
+
* Please address all code review comments.
|
|
16
|
+
* Ensure that docs are updated accordingly if a feature is added.
|
|
17
|
+
|
|
18
|
+
## Commit Messages
|
|
19
|
+
|
|
20
|
+
From [How to Write a Git Commit Message](http://chris.beams.io/posts/git-commit/)
|
|
21
|
+
|
|
22
|
+
#### The seven rules of a great git commit message
|
|
23
|
+
> Keep in mind: This has all been said before.
|
|
24
|
+
|
|
25
|
+
1. Separate subject from body with a blank line
|
|
26
|
+
1. Limit the subject line to 50 characters
|
|
27
|
+
1. Capitalize the subject line
|
|
28
|
+
1. Do not end the subject line with a period
|
|
29
|
+
1. Use the imperative mood in the subject line
|
|
30
|
+
1. Wrap the body at 72 characters
|
|
31
|
+
1. Use the body to explain what and why vs. how
|
|
32
|
+
|
|
33
|
+
## Doc Changes
|
|
34
|
+
|
|
35
|
+
When making doc changes, we want the change to work on both the gitbook and the regular github site. The issue is that non-doc files will not go to the gitbook site, so doc references to non doc files must use the github URL.
|
|
36
|
+
|
|
37
|
+
### Links to other docs:
|
|
38
|
+
* When making references to doc files, use a relative URL path like:
|
|
39
|
+
`[Installation Overview](docs/basics/installation-overview.md)`
|
|
40
|
+
|
|
41
|
+
* When making references to source code files, use a full url path like:
|
|
42
|
+
`[spec/dummy/config/initializers/react_on_rails.rb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/initializers/react_on_rails.rb)`
|
|
43
|
+
|
|
44
|
+
|
data/docs/misc/doctrine.md
CHANGED
|
@@ -19,7 +19,7 @@ The React on Rails setup provides several key components related to front-end de
|
|
|
19
19
|
6. Happiness for us is actively participating in open source, so we want to be where the action is, which is with the npm libraries on github.com.
|
|
20
20
|
7. You can get set up on React on Rails **FAST** using our application generator.
|
|
21
21
|
8. By placing all client-side development inside of the `/client` directory, pure JavaScript developers can productively do development separate from Rails. Instead of Rails APIs, stub APIs on an express server can provide a simple backend, allowing for rapid iteration of UI prototypes.
|
|
22
|
-
9. Just because we're not relying on the Rails asset pipeline for ES6 conversion does not mean that we're deploying Rails apps in any different way. We still use the asset pipeline to include our Webpack compiled JavaScript. This only requires a few small modifications, as explained in our doc [Heroku Deployment](
|
|
22
|
+
9. Just because we're not relying on the Rails asset pipeline for ES6 conversion does not mean that we're deploying Rails apps in any different way. We still use the asset pipeline to include our Webpack compiled JavaScript. This only requires a few small modifications, as explained in our doc [Heroku Deployment](docs/basics/heroku-deployment.md).
|
|
23
23
|
|
|
24
24
|
## Convention over Configuration
|
|
25
25
|
* React on Rails has taken the hard work out of figuring out the JavaScript tooling that works best with Rails. Not only could you spend lots of time researching different tooling, but then you'd have to figure out how to splice it all together. This is where a lot of "JavaScript fatigue" comes from. The following keep the code clean and consistent:
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
# Code Splitting
|
|
1
|
+
# Code Splitting (Outdated)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
_Note: This document is outdated._ Please email [justin@shakacode.com](mailto:justin@shakacode.com)
|
|
4
|
+
if you would be interested in help with code splitting using
|
|
5
|
+
[loadable-components.com](https://loadable-components.com/docs) with React on Rails.
|
|
6
|
+
|
|
7
|
+
-----
|
|
4
8
|
|
|
5
9
|
What is code splitting? From the webpack documentation:
|
|
6
10
|
|
|
@@ -17,11 +21,11 @@ Let's say you're requesting a page that needs to fetch a code chunk from the ser
|
|
|
17
21
|
> (server) <div data-reactroot="
|
|
18
22
|
<!--This comment is here because the comment beginning on line 13 messes up Sublime's markdown parsing-->
|
|
19
23
|
|
|
20
|
-
Different markup is generated on the client than on the server. Why does this happen? When you register a component or
|
|
24
|
+
Different markup is generated on the client than on the server. Why does this happen? When you register a component or render function with `ReactOnRails.register`, react on rails will render the component as soon as the page loads. However, react-router renders a comment while waiting for the code chunk to be fetched from the server. This means that react will tear all of the server rendered code out of the DOM, and then rerender it a moment later once the code chunk arrives from the server, defeating most of the purpose of server rendering.
|
|
21
25
|
|
|
22
26
|
### The solution
|
|
23
27
|
|
|
24
|
-
To prevent this, you have to wait until the code chunk is fetched before doing the initial render on the client side. To accomplish this, react on rails allows you to register a renderer. This works just like registering a
|
|
28
|
+
To prevent this, you have to wait until the code chunk is fetched before doing the initial render on the client side. To accomplish this, react on rails allows you to register a renderer. This works just like registering a render function, except that the function you pass takes three arguments: `renderer(props, railsContext, domNodeId)`, and is responsible for calling `ReactDOM.render` or `ReactDOM.hydrate` to render the component to the DOM. React on rails will automatically detect when a render function takes three arguments, and will **not** call `ReactDOM.render` or `ReactDOM.hydrate`, instead allowing you to control the initial render yourself. Note, you have to be careful to call `ReactDOM.hydrate` rather than `ReactDOM.render` if you are are server rendering.
|
|
25
29
|
|
|
26
30
|
Here's an example of how you might use this in practice:
|
|
27
31
|
|
|
@@ -34,7 +38,7 @@ Here's an example of how you might use this in practice:
|
|
|
34
38
|
|
|
35
39
|
#### clientRegistration.js
|
|
36
40
|
```js
|
|
37
|
-
import ReactOnRails from '
|
|
41
|
+
import ReactOnRails from 'node_package/lib/ReactOnRails';
|
|
38
42
|
import NavigationApp from './NavigationApp';
|
|
39
43
|
|
|
40
44
|
// Note that we're importing a different RouterApp than in serverRegistration.js
|
|
@@ -78,7 +82,7 @@ import { Provider } from 'react-redux';
|
|
|
78
82
|
|
|
79
83
|
import routes from '../routes/routes';
|
|
80
84
|
|
|
81
|
-
|
|
85
|
+
// NOTE how this function takes 3 params, and is thus responsible for calling ReactDOM.render
|
|
82
86
|
const RouterAppRenderer = (props, railsContext, domNodeId) => {
|
|
83
87
|
const store = ReactOnRails.getStore('applicationStore');
|
|
84
88
|
const history = browserHistory;
|
|
@@ -115,7 +119,7 @@ See:
|
|
|
115
119
|
|
|
116
120
|
- [spec/dummy/client/app/startup/clientRegistration.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/clientRegistration.jsx)
|
|
117
121
|
- [spec/dummy/client/app/startup/serverRegistration.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/serverRegistration.jsx)
|
|
118
|
-
- [spec/dummy/client/app/startup/
|
|
122
|
+
- [spec/dummy/client/app/startup/DeferredRenderAppClient](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppClient.jsx)<-- Code splitting implemented here
|
|
119
123
|
- [spec/dummy/client/app/startup/DeferredRenderAppServer.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppServer.jsx)
|
|
120
124
|
- [spec/dummy/client/app/components/DeferredRender.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/components/DeferredRender.jsx)
|
|
121
125
|
- [spec/dummy/client/app/components/DeferredRenderAsyncPage.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/components/DeferredRenderAsyncPage.jsx)
|
|
@@ -130,7 +134,7 @@ If you're going to try to do code splitting with server rendered routes, you'll
|
|
|
130
134
|
|
|
131
135
|
The reason is we do server rendering with ExecJS, which is not capable of doing anything asynchronous. It would be impossible to asyncronously fetch a code chunk while server rendering. See [this issue](https://github.com/shakacode/react_on_rails/issues/477) for a discussion.
|
|
132
136
|
|
|
133
|
-
Also, do not attempt to register a renderer on the server. Instead, register either a
|
|
137
|
+
Also, do not attempt to register a renderer on the server. Instead, register either a render function or a component. If you register a renderer in the server bundle, you'll get an error when react on rails tries to server render the component.
|
|
134
138
|
|
|
135
139
|
## How does Webpack know where to find my code chunks?
|
|
136
140
|
|
|
@@ -146,7 +150,7 @@ config = {
|
|
|
146
150
|
|
|
147
151
|
This causes Webpack to prepend the code chunk filename with `/assets/` in the request url. The react on rails sets up the webpack config to put webpack bundles in `app/assets/javascripts/webpack`, and modifies `config/initializers/assets.rb` so that rails detects the bundles. This means that when we prepend the request url with `/assets/`, rails will know what webpack is asking for.
|
|
148
152
|
|
|
149
|
-
See [rails-assets.md](rails-assets.md) to learn more about static assets.
|
|
153
|
+
See [rails-assets.md](docs/outdated/rails-assets.md) to learn more about static assets.
|
|
150
154
|
|
|
151
155
|
If you forget to set the public path, webpack will request the code chunk at `/{filename}`. This will cause the request to be handled by the Rails router, which will send back a 404 response, assuming that you don't have a catch-all route. In your javascript console, you'll get the following error:
|
|
152
156
|
|
|
@@ -28,13 +28,17 @@ You can see all this on the source for [reactrails.com](https://www.reactrails.c
|
|
|
28
28
|
|
|
29
29
|
## Building the Bundles
|
|
30
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.
|
|
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. Alternately, the `rails/webpacker` library also can ensure that your bundles are built.
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
For example, you might create a [Procfile.dev](spec/dummy/Procfile.dev).
|
|
34
34
|
|
|
35
|
-
On production deployments that use asset precompilation, such as Heroku deployments,
|
|
35
|
+
On production deployments that use asset precompilation, such as Heroku deployments, `rails/webpacker`, by default, will automatically run webpack to build your JavaScript bundles, running the command `bin/webpack` in your app.
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
However, if you want to run a custom command to run webpack to build your bundles, then you will:
|
|
38
|
+
1. Ensure you do not have a `config/webpack/production.js` file
|
|
39
|
+
1. Define `config.build_production_command` in your [config/initializers/react_on_rails.rb](docs/basics/configuration.md)
|
|
40
|
+
|
|
41
|
+
Then React on Rails modifies the `assets:precompile` task to run your `build_production_command`.
|
|
38
42
|
|
|
39
43
|
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.
|
|
40
44
|
|
|
@@ -14,17 +14,17 @@ The only requirements within this directory for basic React on Rails integration
|
|
|
14
14
|
1. Your webpack configuration files:
|
|
15
15
|
1. Create outputs in a directory like `/public/webpack`, which is customizable in your `config/initializers/react_on_rails.rb`.
|
|
16
16
|
1. Provide server rendering if you wish to use that feature.
|
|
17
|
-
1. Your JavaScript code "registers" any components and stores per the ReactOnRails APIs of ReactOnRails.register(components) and ReactOnRails.registerStore(stores). See API docs in [README.md](
|
|
17
|
+
1. Your JavaScript code "registers" any components and stores per the ReactOnRails APIs of ReactOnRails.register(components) and ReactOnRails.registerStore(stores). See API docs in [README.md](README.md) and the [ReactOnRails.js source](../../node_package/src/ReactOnRails.js).
|
|
18
18
|
1. Set your registration file as an "entry" point in your Webpack configs.
|
|
19
19
|
1. Add the [Manifest plugin](https://github.com/danethurber/webpack-manifest-plugin) to your config. For examples see [dummy config](../../spec/dummy/client/webpack.client.base.config.js).
|
|
20
20
|
The default path: `public/webpack` can be loaded with webpackConfigLoader as shown in the dummy example.
|
|
21
21
|
1. You create scripts in `client/package.json` per the example apps. These are used for building your Webpack assets. Also do this for your top level `package.json`.
|
|
22
22
|
|
|
23
23
|
## Rails Steps (outside of /client)
|
|
24
|
-
1. Add `gem "webpacker"` to the Gemfile, run bundle. The gem provides the `stylesheet_pack_tag` and `javascript_pack_tag` helpers which is used to load the bundled assets to your layouts.[Dummy Example](
|
|
25
|
-
1. Configure the `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [spec/dummy/config/initializers/react_on_rails.rb](
|
|
24
|
+
1. Add `gem "webpacker"` to the Gemfile, run bundle. The gem provides the `stylesheet_pack_tag` and `javascript_pack_tag` helpers which is used to load the bundled assets to your layouts.[Dummy Example](spec/dummy/app/views/layouts/application.html.erb)
|
|
25
|
+
1. Configure the `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [spec/dummy/config/initializers/react_on_rails.rb](spec/dummy/config/initializers/react_on_rails.rb) for a detailed example of configuration, including comments on the different values to configure.
|
|
26
26
|
1. Configure your Procfiles per the example apps. These are at the root of your Rails installation.
|
|
27
|
-
1. Configure your top level JavaScript files for inclusion in your layout. You'll want a version that you use for static assets, and you want a file for any files in your setup that are not part of your webpack build. The reason for this is for use with hot-reloading. If you are not using hot reloading, then you only need to configure your `application.js` file to include your Webpack generated files.
|
|
28
|
-
1. If you are deploying to Heroku, see [heroku-deployment.md](/docs/
|
|
27
|
+
1. Configure your top level JavaScript files for inclusion in your layout. You'll want a version that you use for static assets, and you want a file for any files in your setup that are not part of your webpack build. The reason for this is for use with hot-reloading. If you are not using hot reloading, then you only need to configure your `application.js` file to include your Webpack generated files.
|
|
28
|
+
1. If you are deploying to Heroku, see [heroku-deployment.md](/docs/basics/heroku-deployment.md)
|
|
29
29
|
|
|
30
30
|
If I missed anything, please submit a PR or file an issue.
|