react_on_rails 12.0.0.pre.beta.2 → 12.0.0.pre.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -2
- data/README.md +23 -27
- data/SUMMARY.md +1 -1
- data/docs/basics/configuration.md +20 -15
- data/docs/basics/deployment.md +2 -3
- data/docs/basics/heroku-deployment.md +24 -0
- data/docs/basics/i18n.md +3 -3
- data/docs/basics/installation-into-an-existing-rails-app.md +2 -7
- data/docs/basics/recommended-project-structure.md +5 -22
- data/docs/basics/rspec-configuration.md +3 -4
- data/docs/basics/upgrading-react-on-rails.md +11 -9
- data/docs/basics/webpack-configuration.md +3 -7
- data/docs/misc/doctrine.md +1 -1
- data/docs/outdated/how-react-on-rails-works.md +8 -4
- data/docs/outdated/manual-installation-overview.md +1 -1
- data/docs/outdated/rails-assets.md +0 -7
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +2 -0
- data/lib/react_on_rails/configuration.rb +45 -6
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +17 -0
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/webpacker_utils.rb +6 -0
- data/lib/tasks/assets.rake +17 -10
- data/package.json +1 -1
- data/react_on_rails.gemspec +1 -0
- data/yarn.lock +260 -109
- metadata +17 -3
- data/docs/outdated/heroku-deployment.md +0 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4652a34dc5c5b7c6dc27a60c17784219c81ef879adfc86de0ff7022cfb44ccb
|
4
|
+
data.tar.gz: 74606d2bc6faf28ba8e006c939c8d83da5f302c4eeed0a8f7b83bd17af69c418
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4d18a27009cf0916c84f14b78445266de5ede5dbbcc3de944fde3572daff143eedb3b1f81d5856c798e34936ec736b0acf25ccf47e11d8b297b15a404a8db27
|
7
|
+
data.tar.gz: 8afa44acedfa9fcb39cb33883eeed773acb14510973f03bb2a218408d5715dd701ccd88bec1089dd5d8bea8ca52c083e280f9aef57601afb789f3d44181b2533
|
data/CHANGELOG.md
CHANGED
@@ -17,8 +17,8 @@ Changes since last non-beta release.
|
|
17
17
|
*Please add entries here for your pull requests that are not yet released.*
|
18
18
|
|
19
19
|
## UPCOMING 12.0 RELEASE
|
20
|
+
See [docs/basics/upgrading-react-on-rails.md](./docs/basics/upgrading-react-on-rails.md).
|
20
21
|
|
21
|
-
#### Improved
|
22
22
|
### [12.0.0.pre.beta.2]
|
23
23
|
* Changed the precompile task to use the rails/webpacker one by default
|
24
24
|
|
@@ -926,7 +926,9 @@ Best done with Object destructing:
|
|
926
926
|
##### Fixed
|
927
927
|
- Fix several generator related issues.
|
928
928
|
|
929
|
-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.
|
929
|
+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.3...master
|
930
|
+
[12.0.0.pre.beta.3]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.2...12.0.0-beta.3
|
931
|
+
[12.0.0.pre.beta.2]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.1...12.0.0-beta.2
|
930
932
|
[12.0.0.pre.beta.1]: https://github.com/shakacode/react_on_rails/compare/12.0.0-beta.0...12.0.0-beta.1
|
931
933
|
[12.0.0.pre.beta.0]: https://github.com/shakacode/react_on_rails/compare/11.3.0...12.0.0-beta.0
|
932
934
|
[11.3.0]: https://github.com/shakacode/react_on_rails/compare/11.2.2...11.3.0
|
data/README.md
CHANGED
@@ -14,12 +14,17 @@
|
|
14
14
|
*These are the docs for React on Rails 12, coming soon. To see the version 11 docs, [click here](https://github.com/shakacode/react_on_rails/tree/11.3.0).*
|
15
15
|
|
16
16
|
#### News
|
17
|
-
**June
|
18
|
-
1. Gem version: 12.0.0.pre.beta.
|
17
|
+
**June 24, 2020**:
|
18
|
+
1. Gem version: 12.0.0.pre.beta.3 and npm version 12.0.0-beta.3 released! Please try this out!
|
19
19
|
Major enhancements:
|
20
|
-
1.
|
21
|
-
2.
|
20
|
+
1. Proper support for React Hooks
|
21
|
+
2. Typescript bindings
|
22
22
|
3. i18n support for generating a JSON file rather than a JS file.
|
23
|
+
4. Tighter rails/webpacker integration
|
24
|
+
|
25
|
+
Be sure to see the [CHANGELOG.md](./CHANGELOG.md) and read the upgrade instructions:
|
26
|
+
[docs/basics/upgrading-react-on-rails](./docs/basics/upgrading-react-on-rails.md#upgrading-to-v12).
|
27
|
+
|
23
28
|
2. See Justin's RailsConf talk: [Webpacker, It-Just-Works, But How?](http://railsconf.com/2020/video/justin-gordon-webpacker-it-just-works-but-how).
|
24
29
|
|
25
30
|
**April 2, 2020**:
|
@@ -44,21 +49,20 @@ Feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakaco
|
|
44
49
|
|
45
50
|
## Project Objective
|
46
51
|
|
47
|
-
To provide
|
52
|
+
To provide a high performance framework for integrating Ruby on Rails with React via the [**Webpacker**](https://github.com/rails/webpacker) gem especially in regards to React Server Rendering.
|
48
53
|
|
49
54
|
## Features and Why React on Rails?
|
50
55
|
|
51
56
|
Given that rails/webpacker gem already provides basic React integration, why would you use "React on Rails"?
|
52
57
|
|
53
|
-
1. Server rendering, often used for SEO crawler indexing and UX performance, is not offered by rails/webpacker.
|
54
58
|
1. The easy passing of props directly from your Rails view to your React components rather than having your Rails view load and then make a separate request to your API.
|
59
|
+
1. Tight integration with [rails/webpacker](https://github.com/rails/webpacker).
|
60
|
+
1. Server rendering, often used for SEO crawler indexing and UX performance, is not offered by rails/webpacker.
|
55
61
|
1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/reactjs/react-router) integration with server-side-rendering.
|
56
62
|
1. [Internationalization (I18n) and (localization)](https://github.com/shakacode/react_on_rails/blob/master/docs/basics/i18n.md)
|
57
|
-
1. [RSpec Test Helpers Configuration](docs/basics/rspec-configuration.md) to ensure your Webpack bundles are ready for tests. _(and for [Minitest](docs/basics/minitest-configuration.md))._
|
58
63
|
1. A supportive community. This [web search shows how live public sites are using React on Rails](https://publicwww.com/websites/%22react-on-rails%22++-undeveloped.com/).
|
59
64
|
1. [Reason ML Support](https://github.com/shakacode/reason-react-on-rails-example).
|
60
65
|
|
61
|
-
|
62
66
|
See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
|
63
67
|
|
64
68
|
## ShakaCode Forum Premium Content
|
@@ -74,7 +78,7 @@ _Requires creating a free account._
|
|
74
78
|
|
75
79
|
## Prerequisites
|
76
80
|
|
77
|
-
|
81
|
+
Ruby on Rails >=5 and rails/webpacker 4.2+.
|
78
82
|
|
79
83
|
## Getting Started
|
80
84
|
|
@@ -89,23 +93,10 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl
|
|
89
93
|
|
90
94
|
*See also [the instructions for installing into an existing Rails app](docs/basics/installation-into-an-existing-rails-app.md).*
|
91
95
|
|
92
|
-
1. Create a new Rails app:
|
93
|
-
|
94
|
-
``````bash
|
95
|
-
$ rails new my-app --webpack=react
|
96
|
-
$ cd my-app
|
97
|
-
``````
|
98
|
-
|
99
96
|
2. Add the `react_on_rails` gem to Gemfile:
|
100
97
|
|
101
|
-
```ruby
|
102
|
-
gem 'react_on_rails', '11.1.4' # Use the exact gem version to match npm version
|
103
|
-
```
|
104
|
-
|
105
|
-
3. Install the `react_on_rails` gem:
|
106
|
-
|
107
98
|
```bash
|
108
|
-
|
99
|
+
bundle add react_on_rails --strict
|
109
100
|
```
|
110
101
|
|
111
102
|
4. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
|
@@ -113,13 +104,13 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl
|
|
113
104
|
5. Run the generator:
|
114
105
|
|
115
106
|
```bash
|
116
|
-
|
107
|
+
rails generate react_on_rails:install
|
117
108
|
```
|
118
109
|
|
119
110
|
6. Start the app:
|
120
111
|
|
121
112
|
```bash
|
122
|
-
|
113
|
+
rails s
|
123
114
|
```
|
124
115
|
|
125
116
|
7. Visit http://localhost:3000/hello_world.
|
@@ -138,13 +129,18 @@ Below is the line where you turn server rendering on by setting `prerender` to t
|
|
138
129
|
<%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %>
|
139
130
|
```
|
140
131
|
|
132
|
+
Note, if you got an error in your console regarding "ReferenceError: window is not defined",
|
133
|
+
then you need to edit `config/webpacker.yml` and set `hmr: false` and `inline: false`.
|
134
|
+
See [rails/webpacker PR 2644](https://github.com/rails/webpacker/pull/2644) for a fix for this
|
135
|
+
issue.
|
136
|
+
|
141
137
|
## Basic Usage
|
142
138
|
|
143
139
|
### Configuration
|
144
140
|
|
145
141
|
* Configure `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [docs/basics/configuration.md](docs/basics/configuration.md) for documentation of all configuration options.
|
146
|
-
* Configure `config/webpacker.yml`. If you used the generator and the default webpacker setup, you don't need to touch this file. If you are customizing your setup, then consult the [spec/dummy/config/webpacker.yml](./spec/dummy/config/webpacker.yml) example
|
147
|
-
*
|
142
|
+
* Configure `config/webpacker.yml`. If you used the generator and the default webpacker setup, you don't need to touch this file. If you are customizing your setup, then consult the [spec/dummy/config/webpacker.yml](./spec/dummy/config/webpacker.yml) example or the official default [webpacker.yml](https://github.com/rails/webpacker/blob/master/lib/install/config/webpacker.yml).
|
143
|
+
* Tip: set `compile: false` for development if you know that you'll always be compiling with a watch process. Otherwise, every request will check if compilation is needed.
|
148
144
|
* Your `public_output_path` must match your Webpack configuration for `output` of your bundles.
|
149
145
|
* Only set `cache_manifest` to `true` in your production env.
|
150
146
|
|
data/SUMMARY.md
CHANGED
@@ -45,7 +45,7 @@
|
|
45
45
|
+ [AngularJS Integration and Migration to React on Rails](./docs/additional-reading/angular-js-integration-migration.md)
|
46
46
|
|
47
47
|
## **Deployment**
|
48
|
-
+ [Heroku Deployment](docs/
|
48
|
+
+ [Heroku Deployment](docs/basics/heroku-deployment.md)
|
49
49
|
+ [Elastic Beanstalk Deployment](./docs/additional-reading/elastic-beanstalk.md)
|
50
50
|
|
51
51
|
## Outdated Non-Webpack Docs
|
@@ -12,21 +12,27 @@ default: &default
|
|
12
12
|
# public_output_path folder
|
13
13
|
manifest: manifest.json
|
14
14
|
cache_manifest: false
|
15
|
+
|
16
|
+
# Source path is used to check if webpack compilation needs to be run for `compile: true`
|
15
17
|
source_path: client/app
|
16
18
|
|
17
19
|
development:
|
18
20
|
<<: *default
|
19
|
-
#
|
21
|
+
# Generated files for development, in /public/webpack/dev
|
20
22
|
public_output_path: webpack/dev
|
21
23
|
|
22
24
|
test:
|
23
25
|
<<: *default
|
24
|
-
#
|
26
|
+
# Ensure that webpacker invokes webpack to build files for tests if not using the
|
27
|
+
# ReactOnRails rspec helper.
|
28
|
+
compile: true
|
29
|
+
|
30
|
+
# Generated files for tests, in /public/webpack/test
|
25
31
|
public_output_path: webpack/test
|
26
32
|
|
27
33
|
production:
|
28
34
|
<<: *default
|
29
|
-
#
|
35
|
+
# Generated files for production, in /public/webpack/production
|
30
36
|
public_output_path: webpack/production
|
31
37
|
cache_manifest: true
|
32
38
|
```
|
@@ -45,7 +51,7 @@ ReactOnRails.configure do |config|
|
|
45
51
|
# The default is true for development, off otherwise.
|
46
52
|
# With true, you get detailed logs of rendering and stack traces if you call setTimout,
|
47
53
|
# setInterval, clearTimout when server rendering.
|
48
|
-
config.trace = Rails.env.development?
|
54
|
+
config.trace = Rails.env.development? # default
|
49
55
|
|
50
56
|
# Configure if default DOM IDs have a random value or are fixed.
|
51
57
|
# false ==> Sets the dom id to "#{react_component_name}-react-component"
|
@@ -54,18 +60,17 @@ ReactOnRails.configure do |config|
|
|
54
60
|
# it is convenient to set this to true or else you have to either manually set the ids to
|
55
61
|
# avoid collisions. Most newer apps will have only one instance of a component on a page,
|
56
62
|
# so this should be false in most cases.
|
57
|
-
# This value can be
|
58
|
-
config.random_dom_id =
|
63
|
+
# This value can be overridden for a given call to react_component
|
64
|
+
config.random_dom_id = true # default
|
59
65
|
|
60
|
-
# defaults to "" (top level)
|
61
|
-
#
|
62
|
-
|
63
|
-
|
64
|
-
#
|
65
|
-
# if you
|
66
|
-
#
|
67
|
-
#
|
68
|
-
# If that file exists, React on Rails thinks that you'll use the rails/webpacker bin/webpack compiler.
|
66
|
+
# defaults to "" (top level)
|
67
|
+
config.node_modules_location = "client" # If using webpacker you should use "".
|
68
|
+
|
69
|
+
# This configures the script to run to build the production assets by webpack . Set this to nil
|
70
|
+
# if you don't want react_on_rails building this file for you.
|
71
|
+
# Note, if you want to use this command then you should remove the file
|
72
|
+
# config/webpack/production.js
|
73
|
+
# If that file exists, React on Rails thinks that you'll use the rails/webpacker bin/webpack compiler.
|
69
74
|
config.build_production_command = "RAILS_ENV=production bin/webpack"
|
70
75
|
|
71
76
|
################################################################################
|
data/docs/basics/deployment.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# Deployment
|
2
2
|
|
3
|
-
-
|
4
|
-
|
5
|
-
- See the [Heroku Deployment](docs/outdated/heroku-deployment.md) doc for specifics regarding Heroku. The information for Heroku may apply to other deployments.
|
3
|
+
- `rails/webpacker` puts the necessary precompile steps automatically in the rake precompile step.
|
4
|
+
- See the [Heroku Deployment](docs/basics/heroku-deployment.md) doc for specifics regarding Heroku. The information for Heroku may apply to other deployments.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Heroku Deployment
|
2
|
+
## Heroku buildpacks
|
3
|
+
|
4
|
+
React on Rails requires both a ruby environment (for Rails) and a Node environment (for Webpack), so you will need to have Heroku use multiple buildpacks.
|
5
|
+
|
6
|
+
Assuming you have downloaded and installed the Heroku command-line utility and have initialized the app, you will need to tell Heroku to use both buildpacks via the command-line:
|
7
|
+
|
8
|
+
```
|
9
|
+
heroku buildpacks:set heroku/ruby
|
10
|
+
heroku buildpacks:add --index 1 heroku/nodejs
|
11
|
+
```
|
12
|
+
|
13
|
+
For more information, see [Using Multiple Buildpacks for an App](https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app)
|
14
|
+
|
15
|
+
## assets:precompile
|
16
|
+
|
17
|
+
### rails/webpacker webpack configuration
|
18
|
+
If you're using the standard rails/webpacker configuration of webpack, then rails/webpacker
|
19
|
+
will automatically modify or create an assets:precompile task to build your assets.
|
20
|
+
|
21
|
+
### custom webpack configuration
|
22
|
+
If you're a custom webpack configuration, and you **do not have the default
|
23
|
+
`config/webpack/production.js`** file, then the `config/initializers/react_on_rails.rb`
|
24
|
+
configuration `config.build_production_command` will be used.
|
data/docs/basics/i18n.md
CHANGED
@@ -25,7 +25,7 @@ Here's a summary of adding the I18n functionality.
|
|
25
25
|
|
26
26
|
3. Javascript locale files must be generated before `yarn build`.
|
27
27
|
|
28
|
-
Once you setup `config.i18n_dir` as in the previous step,
|
28
|
+
Once you setup `config.i18n_dir` as in the previous step, you will need to make sure `rake react_on_rails:locale` runs before webpack.
|
29
29
|
|
30
30
|
For development, you should adjust your startup scripts (Procfiles) so that they run **`bundle exec rake react_on_rails:locale`** before running any webpack watch process (`yarn run build:development`).
|
31
31
|
|
@@ -48,6 +48,7 @@ with `react-intl` supported via js files:
|
|
48
48
|
```
|
49
49
|
|
50
50
|
2. Add `react-intl` & `intl` to `client/package.json`, and remember to `bundle && yarn install`.
|
51
|
+
Versions should be newer than these:
|
51
52
|
|
52
53
|
```js
|
53
54
|
"dependencies": {
|
@@ -93,7 +94,6 @@ with `react-intl` supported via js files:
|
|
93
94
|
```
|
94
95
|
|
95
96
|
# Notes
|
96
|
-
|
97
97
|
* See why using JSON could be better compare to JS if amount of data is hure [ https://v8.dev/blog/cost-of-javascript-2019#json]( https://v8.dev/blog/cost-of-javascript-2019#json).
|
98
98
|
* See [Support for Rails' i18n pluralization #1000](https://github.com/shakacode/react_on_rails/issues/1000) for a discussion of issues around pluralization.
|
99
|
-
*
|
99
|
+
* *Outdated:* You can refer to [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) and [PR #340](https://github.com/shakacode/react-webpack-rails-tutorial/pull/340), [commmited](https://github.com/shakacode/react-webpack-rails-tutorial/commit/ef369ed9d922aea5116ca7e50208169fd7831389) for a complete example.
|
@@ -7,8 +7,8 @@
|
|
7
7
|
1. Add the following to your Gemfile and `bundle install`. We recommend fixing the version of React on Rails, as you will need to keep the exact version in sync with the version in your `client/package.json` file.
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem "react_on_rails", "
|
11
|
-
gem "webpacker", "~>
|
10
|
+
gem "react_on_rails", "12.0.0" # Update to the current version
|
11
|
+
gem "webpacker", "~> 5"
|
12
12
|
```
|
13
13
|
|
14
14
|
2. Run the following 2 commands to install Webpacker with React. Note, if you are using an older version of Rails than 5.1, you'll need to install webpacker with React per the instructions [here](https://github.com/rails/webpacker).
|
@@ -57,8 +57,3 @@ $ yarn add react-on-rails --exact
|
|
57
57
|
```
|
58
58
|
|
59
59
|
That will install the latest version and update your package.json. **NOTE:** the `--exact` flag will ensure that you do not have a "~" or "^" for your react-on-rails version in your package.json.
|
60
|
-
|
61
|
-
## Webpacker Configuration
|
62
|
-
|
63
|
-
React on Rails users should set configuration value `compile` to false, as React on Rails handles compilation for test and production environments.
|
64
|
-
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# Recommended Project structure
|
2
2
|
|
3
|
-
While React On Rails does not *enforce* a specific project structure, we do *recommend* a standard organization. The more we follow standards as a community, the easier it will be for all of us to move between various Rails projects that include React On Rails.
|
4
|
-
|
5
3
|
The React on Rails generator uses the standard `rails/webpacker` convention of this structure:
|
6
4
|
|
7
5
|
```yml
|
@@ -14,21 +12,9 @@ app/javascript:
|
|
14
12
|
│ └── hello-world-bundle.js
|
15
13
|
```
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
1. No support for different entry points for server rendering.
|
20
|
-
2. Webpacker adds an extra layer of abstraction over Webpack, which you probably don't want.
|
21
|
-
|
22
|
-
This default rails/webpacker configuration is used for the generator because:
|
23
|
-
|
24
|
-
1. Minimizes the amount of generated code to get up and running with React on Rails.
|
25
|
-
2. Good enough for very simple projects.
|
26
|
-
3. Configuration of Webpack is not the goal of this library, React on Rails.
|
15
|
+
However, you may wish to move all your client side files to a single directory called something like `/client`.
|
27
16
|
|
28
|
-
|
29
|
-
Thus, the generator structure and using rails/webpacker for Webpack configuration **is not recommended** for any commercial projects, especially those that will use server rendering. Instead, the recommended structure is shown in this example app: [github.com/shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) and described below.
|
30
|
-
|
31
|
-
## Steps to convert from the generator defaults to use the recommended `/client` directory structure.
|
17
|
+
## Steps to convert from the generator defaults to use a `/client` directory structure.
|
32
18
|
|
33
19
|
1. Move the directory:
|
34
20
|
|
@@ -44,7 +30,7 @@ mv app/javascript client
|
|
44
30
|
|
45
31
|
## Moving node_modules from `/` to `/client` with a custom webpack setup.
|
46
32
|
|
47
|
-
`rails/webpacker` probably doesn't support having your main node_modules directory under `/client`, so only follow these steps if you want to use your own webpack configuration
|
33
|
+
`rails/webpacker` probably doesn't support having your main node_modules directory under `/client`, so only follow these steps if you want to use your own webpack configuration.
|
48
34
|
|
49
35
|
1. Move the `/package.json` to `/client/package.json`
|
50
36
|
2. Create a `/package.json` that delegates to `/client/package.json`. See the example in [spec/dummy/package.json](../../spec/dummy/package.json).
|
@@ -57,7 +43,7 @@ mv app/javascript client
|
|
57
43
|
1. `/client/app/bundles`: Top level of different app domains. Use a name within this directory for you app domains. For example, if you had a domain called `widget-editing`, then you would have: `/client/app/bundles/widget-editing`
|
58
44
|
1. `/client/app/lib`: Common code for bundles
|
59
45
|
1. Within each bundle directory (or the lib directory), such as a domain named "comments"
|
60
|
-
`/client/app/bundles/comments`, use following directory structure:
|
46
|
+
`/client/app/bundles/comments`, use following directory structure, if you're using redux. However, with React hooks, this will probably be a bit different:
|
61
47
|
|
62
48
|
* `/actions`: Redux actions.
|
63
49
|
* `/components`: "dumb" components (no connections to Redux or Ajax). These get props and can render themselves and children.
|
@@ -79,7 +65,7 @@ This isn't really any technique, as you keep handling all your styling assets us
|
|
79
65
|
1. Much simpler! There's no changes really from your current processes.
|
80
66
|
|
81
67
|
### Using Webpack to Manage Styling Assets
|
82
|
-
This technique involves customization of the webpack config files to generate CSS, image, and font assets.
|
68
|
+
This technique involves customization of the webpack config files to generate CSS, image, and font assets.
|
83
69
|
|
84
70
|
#### Directory structure
|
85
71
|
1. `/client/app/assets`: Assets for CSS for client app.
|
@@ -89,6 +75,3 @@ This technique involves customization of the webpack config files to generate CS
|
|
89
75
|
1. You can use [CSS modules](https://github.com/css-modules/css-modules), which is super compelling once you seen the benefits.
|
90
76
|
1. You can do hot reloading of your assets. Thus, you do not have to refresh your web page to see asset change, including changing styles.
|
91
77
|
1. You can run your client code on a mocked out express server for super fast prototyping. In other words, your client application can somewhat more easily be move to a different application server.
|
92
|
-
|
93
|
-
#### Updates 2017-03-04 Regarding CSS handled by Webpack
|
94
|
-
* See article [Best practices for CSS and CSS Modules using Webpack](https://forum.shakacode.com/t/best-practices-for-css-and-css-modules-using-webpack/799).
|
@@ -12,8 +12,7 @@ compiled by webpack before running tests and during production deployment:
|
|
12
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
13
|
|
14
14
|
```yml
|
15
|
-
config.
|
16
|
-
config.build_test_command = "RAILS_ENV=test bin/webpack"
|
15
|
+
config.build_test_command = "NODE_ENV=test RAILS_ENV=test bin/webpack"
|
17
16
|
```
|
18
17
|
|
19
18
|
Which should you use? If you're already using the `rails/webpacker` way to configure webpack, then
|
@@ -45,11 +44,11 @@ If you are using Webpack to build CSS assets, you should do something like this
|
|
45
44
|
```
|
46
45
|
|
47
46
|
Please take note of the following:
|
48
|
-
- 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.
|
49
48
|
|
50
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`
|
51
50
|
|
52
|
-
- 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.
|
53
52
|
|
54
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.
|
55
54
|
|
@@ -6,23 +6,25 @@ If you would like help in migrating between React on Rails versions or help with
|
|
6
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
7
|
|
8
8
|
## Upgrading to v12
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
13
15
|
* If you're using the internalization helper, then set `config.i18n_output_format = 'js'`. You can
|
14
|
-
later update to the default JSON format as you will need to update your usage of that file.
|
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.
|
15
18
|
|
16
|
-
|
19
|
+
### Updated API for `ReactOnRails.register()`
|
17
20
|
|
18
21
|
In order to solve the issues regarding React Hooks compatibility, the number of parameters
|
19
22
|
for functions is used to determine if you have a render function that will get invoked to
|
20
23
|
return a React component, or you are registering a React component defined by a function.
|
21
24
|
|
22
|
-
Registered Objects are of the following types:
|
23
|
-
|
24
25
|
##### Correct
|
25
|
-
|
26
|
+
|
27
|
+
Registered Objects are of the following types. Either of these will work:
|
26
28
|
1. Take **2 params** and return **a React function or class component**. A function component is a function
|
27
29
|
that takes zero or one params and returns a React Element, like JSX.
|
28
30
|
```js
|
@@ -17,11 +17,11 @@ A key decision in your use React on Rails is whether you go with the rails/webpa
|
|
17
17
|
|
18
18
|
## Option 1: Recommended: Traditional React on Rails using the /client directory
|
19
19
|
|
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`.
|
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
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
|
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.
|
23
23
|
|
24
|
-
|
24
|
+
An examples of this pattern is the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial).
|
25
25
|
|
26
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).
|
27
27
|
|
@@ -45,10 +45,6 @@ Typical rails/webpacker apps have a standard directory structure as documented [
|
|
45
45
|
|
46
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/).
|
47
47
|
|
48
|
-
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.
|
49
|
-
|
50
48
|
You can find more details on this topic in [Recommended Project Structure](./recommended-project-structure.md).
|
51
49
|
|
52
50
|
See [Issue 982: Tutorial Generating Correct Project Structure?](https://github.com/shakacode/react_on_rails/issues/982) to discuss this issue.
|
53
|
-
|
54
|
-
For more details on project setup, see [Recommended Project Structure](./docs/basics/recommended-project-structure.md).
|