react_on_rails 13.2.0 → 13.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +5 -2
- data/.github/workflows/lint-js-and-ruby.yml +3 -3
- data/.github/workflows/main.yml +15 -13
- data/.github/workflows/package-js-tests.yml +2 -2
- data/.github/workflows/rspec-package-specs.yml +2 -2
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +11 -1
- data/Gemfile.development_dependencies +1 -1
- data/README.md +5 -5
- data/docs/getting-started.md +11 -5
- data/docs/guides/configuration.md +23 -18
- data/docs/guides/file-system-based-automated-bundle-generation.md +2 -0
- data/docs/guides/installation-into-an-existing-rails-app.md +18 -20
- data/docs/guides/tutorial.md +35 -31
- data/lib/generators/react_on_rails/base_generator.rb +15 -10
- data/lib/generators/react_on_rails/bin/dev +33 -0
- data/lib/generators/react_on_rails/bin/dev-static +33 -0
- data/lib/generators/react_on_rails/install_generator.rb +5 -0
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +1 -1
- data/lib/react_on_rails/configuration.rb +40 -3
- data/lib/react_on_rails/helper.rb +21 -23
- data/lib/react_on_rails/packs_generator.rb +30 -101
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +1 -1
- data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +1 -20
- data/lib/react_on_rails/utils.rb +26 -0
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/webpacker_utils.rb +54 -3
- data/lib/tasks/generate_packs.rake +1 -1
- data/package.json +29 -28
- data/yarn.lock +2856 -3277
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e61be8a6315e32bd3127d5ed676e1235c9e44cb43ff011dde722947c4f18b518
|
4
|
+
data.tar.gz: 61be21f2eda6b8a58688af7a69f88b70c2b0dbfe23a9addf68f2894829e96787
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '069f91f435f7609c582a197e100e0140c9d4045b472fa163a06819847d860a339d0fba56ab408d32aa7307cb2b1205dfd5387b6e503810897a4898d6acf56dee'
|
7
|
+
data.tar.gz: ed764a94f2cf6b4ff1a50d605c73cab97371e0a0bc68bb344bc1978988c54b213b44cbc2bce6f6045158d662e7e8201e829f801df2a07392394dfcfcade3e3d4
|
data/.circleci/config.yml
CHANGED
@@ -205,6 +205,9 @@ jobs:
|
|
205
205
|
- run: *install-yalc-add-react-on-rails
|
206
206
|
- run: *install-dummy-app-node-modules
|
207
207
|
- run: *install-dummy-app-ruby-gems
|
208
|
+
- run:
|
209
|
+
name: generate file system-based packs
|
210
|
+
command: cd spec/dummy && bundle exec rake react_on_rails:generate_packs
|
208
211
|
- run:
|
209
212
|
name: Build test bundles for dummy app
|
210
213
|
command: cd spec/dummy && yarn run build:test
|
@@ -269,12 +272,12 @@ jobs:
|
|
269
272
|
name: Prep for CI
|
270
273
|
# TODO -- need to leverage Circle CI containers
|
271
274
|
command: |
|
272
|
-
bundle exec
|
275
|
+
bundle exec rails prepare_for_ci
|
273
276
|
- run:
|
274
277
|
name: Main CI
|
275
278
|
# TODO -- need to leverage Circle CI containers
|
276
279
|
command: |
|
277
|
-
bundle exec
|
280
|
+
bundle exec rails run_rspec:all_dummy
|
278
281
|
# The following step will run only if the main job is finished successfully.
|
279
282
|
# Build hook is triggered by curl command described here https://docs.netlify.com/configure-builds/build-hooks/
|
280
283
|
# NETLIFY_HOOK is an environment variable on CircleCI to keep sensitive data outside the repo
|
@@ -8,7 +8,7 @@ jobs:
|
|
8
8
|
matrix:
|
9
9
|
ruby: [2.7]
|
10
10
|
node: [14]
|
11
|
-
runs-on: ubuntu-
|
11
|
+
runs-on: ubuntu-22.04
|
12
12
|
steps:
|
13
13
|
- uses: actions/checkout@v2
|
14
14
|
- name: Setup Ruby
|
@@ -32,12 +32,12 @@ jobs:
|
|
32
32
|
uses: actions/cache@v2
|
33
33
|
with:
|
34
34
|
path: node_modules
|
35
|
-
key:
|
35
|
+
key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
|
36
36
|
- name: Save root ruby gems to cache
|
37
37
|
uses: actions/cache@v2
|
38
38
|
with:
|
39
39
|
path: vendor/bundle
|
40
|
-
key:
|
40
|
+
key: v5-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}
|
41
41
|
- name: Install Node modules with Yarn for renderer package
|
42
42
|
run: |
|
43
43
|
yarn install --no-progress --no-emoji
|
data/.github/workflows/main.yml
CHANGED
@@ -8,7 +8,7 @@ jobs:
|
|
8
8
|
matrix:
|
9
9
|
ruby: [2.7]
|
10
10
|
node: [14]
|
11
|
-
runs-on: ubuntu-
|
11
|
+
runs-on: ubuntu-22.04
|
12
12
|
steps:
|
13
13
|
- uses: actions/checkout@v2
|
14
14
|
- name: Setup Ruby
|
@@ -36,7 +36,7 @@ jobs:
|
|
36
36
|
uses: actions/cache@v2
|
37
37
|
with:
|
38
38
|
path: node_modules
|
39
|
-
key:
|
39
|
+
key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
|
40
40
|
- name: Install Node modules with Yarn for renderer package
|
41
41
|
run: |
|
42
42
|
yarn install --no-progress --no-emoji
|
@@ -48,7 +48,7 @@ jobs:
|
|
48
48
|
uses: actions/cache@v2
|
49
49
|
with:
|
50
50
|
path: spec/dummy/node_modules
|
51
|
-
key:
|
51
|
+
key: v5-dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/yarn.lock') }}
|
52
52
|
- name: yalc add react-on-rails
|
53
53
|
run: cd spec/dummy && yalc add react-on-rails
|
54
54
|
- name: Install Node modules with Yarn for dummy app
|
@@ -57,9 +57,11 @@ jobs:
|
|
57
57
|
uses: actions/cache@v2
|
58
58
|
with:
|
59
59
|
path: spec/dummy/vendor/bundle
|
60
|
-
key:
|
60
|
+
key: v5-dummy-app-gem-cache-${{ hashFiles('spec/dummy/Gemfile.lock') }}
|
61
61
|
- name: Install Ruby Gems for dummy app
|
62
62
|
run: cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
63
|
+
- name: generate file system-based packs
|
64
|
+
run: cd spec/dummy && RAILS_ENV=test bundle exec rake react_on_rails:generate_packs
|
63
65
|
- name: Build test bundles for dummy app
|
64
66
|
run: cd spec/dummy && yarn run build:test
|
65
67
|
- id: get-sha
|
@@ -68,7 +70,7 @@ jobs:
|
|
68
70
|
uses: actions/cache@v2
|
69
71
|
with:
|
70
72
|
path: spec/dummy/public/webpack
|
71
|
-
key:
|
73
|
+
key: v5-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }}
|
72
74
|
|
73
75
|
main:
|
74
76
|
needs: build-dummy-app-webpack-test-bundles
|
@@ -77,7 +79,7 @@ jobs:
|
|
77
79
|
ruby: [2.7]
|
78
80
|
node: [14]
|
79
81
|
rake_task: ['run_rspec:all_dummy', 'run_rspec:all_but_examples', 'run_rspec:examples']
|
80
|
-
runs-on: ubuntu-
|
82
|
+
runs-on: ubuntu-22.04
|
81
83
|
steps:
|
82
84
|
- uses: actions/checkout@v2
|
83
85
|
- name: Setup Ruby
|
@@ -101,29 +103,29 @@ jobs:
|
|
101
103
|
uses: actions/cache@v2
|
102
104
|
with:
|
103
105
|
path: node_modules
|
104
|
-
key:
|
106
|
+
key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
|
105
107
|
- name: Save root ruby gems to cache
|
106
108
|
uses: actions/cache@v2
|
107
109
|
with:
|
108
110
|
path: vendor/bundle
|
109
|
-
key:
|
111
|
+
key: v5-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}
|
110
112
|
- name: Save dummy app ruby gems to cache
|
111
113
|
uses: actions/cache@v2
|
112
114
|
with:
|
113
115
|
path: spec/dummy/vendor/bundle
|
114
|
-
key:
|
116
|
+
key: v5-dummy-app-gem-cache-${{ hashFiles('spec/dummy/Gemfile.lock') }}
|
115
117
|
- name: Save spec/dummy/node_modules to cache
|
116
118
|
uses: actions/cache@v2
|
117
119
|
with:
|
118
120
|
path: spec/dummy/node_modules
|
119
|
-
key:
|
121
|
+
key: v5-dummy-app-node-modules-cache-${{ hashFiles('spec/dummy/yarn.lock') }}
|
120
122
|
- id: get-sha
|
121
123
|
run: echo "::set-output name=sha::$(git rev-parse HEAD)"
|
122
124
|
- name: Save test webpack bundles to cache (for build number checksum used by rspec job)
|
123
125
|
uses: actions/cache@v2
|
124
126
|
with:
|
125
127
|
path: spec/dummy/public/webpack
|
126
|
-
key:
|
128
|
+
key: v5-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }}
|
127
129
|
|
128
130
|
- name: Install Node modules with Yarn for renderer package
|
129
131
|
run: |
|
@@ -157,9 +159,9 @@ jobs:
|
|
157
159
|
- name: Increase the amount of inotify watchers
|
158
160
|
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
|
159
161
|
- name: Prep for CI
|
160
|
-
run: bundle exec
|
162
|
+
run: bundle exec rails prepare_for_ci
|
161
163
|
- name: Main CI
|
162
|
-
run: bundle exec
|
164
|
+
run: bundle exec rails ${{ matrix.rake_task }}
|
163
165
|
- name: Store test results
|
164
166
|
uses: actions/upload-artifact@v2
|
165
167
|
with:
|
@@ -7,7 +7,7 @@ jobs:
|
|
7
7
|
strategy:
|
8
8
|
matrix:
|
9
9
|
node: [12, 14]
|
10
|
-
runs-on: ubuntu-
|
10
|
+
runs-on: ubuntu-22.04
|
11
11
|
steps:
|
12
12
|
- uses: actions/checkout@v2
|
13
13
|
- name: Setup Node
|
@@ -25,7 +25,7 @@ jobs:
|
|
25
25
|
uses: actions/cache@v2
|
26
26
|
with:
|
27
27
|
path: node_modules
|
28
|
-
key:
|
28
|
+
key: v5-package-node-modules-cache-${{ hashFiles('yarn.lock') }}
|
29
29
|
- name: Install Node modules with Yarn for renderer package
|
30
30
|
run: |
|
31
31
|
yarn install --no-progress --no-emoji
|
@@ -8,7 +8,7 @@ jobs:
|
|
8
8
|
matrix:
|
9
9
|
ruby: [2.7]
|
10
10
|
node: [14]
|
11
|
-
runs-on: ubuntu-
|
11
|
+
runs-on: ubuntu-22.04
|
12
12
|
steps:
|
13
13
|
- uses: actions/checkout@v2
|
14
14
|
- name: Setup Ruby
|
@@ -28,7 +28,7 @@ jobs:
|
|
28
28
|
uses: actions/cache@v2
|
29
29
|
with:
|
30
30
|
path: vendor/bundle
|
31
|
-
key:
|
31
|
+
key: v5-package-app-gem-cache-${{ hashFiles('react_on_rails.gemspec') }}
|
32
32
|
- name: Install Ruby Gems for package
|
33
33
|
run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
34
34
|
- name: Run rspec tests
|
data/.rubocop.yml
CHANGED
@@ -94,6 +94,8 @@ RSpec/AnyInstance:
|
|
94
94
|
Exclude:
|
95
95
|
- 'spec/react_on_rails/git_utils_spec.rb'
|
96
96
|
- 'spec/react_on_rails/locales_to_js_spec.rb'
|
97
|
+
- 'spec/react_on_rails/binstubs/dev_spec.rb'
|
98
|
+
- 'spec/react_on_rails/binstubs/dev_static_spec.rb'
|
97
99
|
|
98
100
|
RSpec/DescribeClass:
|
99
101
|
Enabled: false
|
@@ -111,6 +113,8 @@ RSpec/BeforeAfterAll:
|
|
111
113
|
Exclude:
|
112
114
|
- 'spec/react_on_rails/generators/dev_tests_generator_spec.rb'
|
113
115
|
- 'spec/react_on_rails/generators/install_generator_spec.rb'
|
116
|
+
- 'spec/react_on_rails/binstubs/dev_spec.rb'
|
117
|
+
- 'spec/react_on_rails/binstubs/dev_static_spec.rb'
|
114
118
|
|
115
119
|
RSpec/MessageChain:
|
116
120
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -17,6 +17,15 @@ Changes since last non-beta release.
|
|
17
17
|
|
18
18
|
*Please add entries here for your pull requests that are not yet released.*
|
19
19
|
|
20
|
+
### [13.3.0] - 2022-01-29
|
21
|
+
### Fixed
|
22
|
+
- Fixed pack not found warning while using `react_component` and `react_component_hash` helpers, even when corresponding chunks are present. [PR 1511](https://github.com/shakacode/react_on_rails/pull/1511) by [pulkitkkr](https://github.com/pulkitkkr)
|
23
|
+
- Fixed FS-based packs generation functionality to trigger pack generation on the creation of a new react component inside `components_subdirectory`. [PR 1506](https://github.com/shakacode/react_on_rails/pull/1506) by [pulkitkkr](https://github.com/pulkitkkr)
|
24
|
+
- Upgrade several JS dependencies to fix security issues. [PR 1514](https://github.com/shakacode/react_on_rails/pull/1514) by [ahangarha](https://github.com/ahangarha)
|
25
|
+
|
26
|
+
### Added
|
27
|
+
- Added `./bin/dev` and `./bin/dev-static` executables to ease and standardize running the dev server. [PR 1491](https://github.com/shakacode/react_on_rails/pull/1491) by [ahangarha](https://github.com/ahangarha)
|
28
|
+
|
20
29
|
### [13.2.0] - 2022-12-23
|
21
30
|
|
22
31
|
### Fixed
|
@@ -1051,7 +1060,8 @@ Best done with Object destructing:
|
|
1051
1060
|
##### Fixed
|
1052
1061
|
- Fix several generator related issues.
|
1053
1062
|
|
1054
|
-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/13.
|
1063
|
+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/13.3.0...master
|
1064
|
+
[13.3.0]: https://github.com/shakacode/react_on_rails/compare/13.2.0...13.3.0
|
1055
1065
|
[13.2.0]: https://github.com/shakacode/react_on_rails/compare/13.1.0...13.2.0
|
1056
1066
|
[13.1.0]: https://github.com/shakacode/react_on_rails/compare/13.0.2...13.1.0
|
1057
1067
|
[13.0.2]: https://github.com/shakacode/react_on_rails/compare/13.0.1...13.0.2
|
data/README.md
CHANGED
@@ -98,6 +98,11 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
98
98
|
|
99
99
|
# Supporters
|
100
100
|
|
101
|
+
The following companies support our open source projects, and ShakaCode uses their products!
|
102
|
+
|
103
|
+
<br />
|
104
|
+
<br />
|
105
|
+
|
101
106
|
<a href="https://www.jetbrains.com">
|
102
107
|
<img src="https://user-images.githubusercontent.com/4244251/184881139-42e4076b-024b-4b30-8c60-c3cd0e758c0a.png" alt="JetBrains" height="120px">
|
103
108
|
</a>
|
@@ -122,8 +127,3 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
122
127
|
<a href="https://www.honeybadger.io">
|
123
128
|
<img src="https://user-images.githubusercontent.com/4244251/184881133-79ee9c3c-8165-4852-958e-31687b9536f4.png" alt="Honeybadger" height="55px">
|
124
129
|
</a>
|
125
|
-
|
126
|
-
<br />
|
127
|
-
<br />
|
128
|
-
|
129
|
-
The following companies support our open source projects, and ShakaCode uses their products!
|
data/docs/getting-started.md
CHANGED
@@ -14,13 +14,20 @@ generated using `rails new my_app --javascript=webpack`). If your
|
|
14
14
|
application is not yet set up to use webpacker, please see
|
15
15
|
[the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/).*
|
16
16
|
|
17
|
-
1. Add the `react_on_rails` gem to Gemfile:
|
17
|
+
1. Add the `shakapacker` and `react_on_rails` gem to Gemfile:
|
18
18
|
|
19
19
|
```bash
|
20
|
+
bundle add shakapacker --strict
|
20
21
|
bundle add react_on_rails --strict
|
21
22
|
```
|
22
23
|
|
23
|
-
2.
|
24
|
+
2. Run installation command for webpacker:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
rails webpacker:install
|
28
|
+
```
|
29
|
+
|
30
|
+
3. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
|
24
31
|
|
25
32
|
3. Run the generator:
|
26
33
|
|
@@ -30,9 +37,8 @@ application is not yet set up to use webpacker, please see
|
|
30
37
|
|
31
38
|
4. Start the app:
|
32
39
|
|
33
|
-
|
34
|
-
|
35
|
-
```
|
40
|
+
- Run `./bin/dev` for HMR
|
41
|
+
- Run `./bin/dev-static` for statically created bundles (no HMR)
|
36
42
|
|
37
43
|
5. Visit http://localhost:3000/hello_world.
|
38
44
|
|
@@ -47,6 +47,11 @@ for all client files, including your sources and node_modules.
|
|
47
47
|
# NOTE: you typically will leave the commented out configurations set to their defaults.
|
48
48
|
# Thus, you only need to pay careful attention to the non-commented settings in this file.
|
49
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
|
+
|
50
55
|
# `trace`: General debugging flag.
|
51
56
|
# The default is true for development, off otherwise.
|
52
57
|
# With true, you get detailed logs of rendering and stack traces if you call setTimout,
|
@@ -74,6 +79,10 @@ ReactOnRails.configure do |config|
|
|
74
79
|
# In this example, the module BuildProductionCommand would have a class method `call`.
|
75
80
|
config.build_production_command = "RAILS_ENV=production bin/webpacker"
|
76
81
|
|
82
|
+
# NOTE:
|
83
|
+
# When specifying `build_production_command`, you need to disable `rails/webpacker`
|
84
|
+
# configuration by setting `webpacker_precompile: false` in your `config/webpacker.yml` file.
|
85
|
+
|
77
86
|
# See bottom for an example of the BuildProductionCommand module.
|
78
87
|
# config.build_production_command = BuildProductionCommand
|
79
88
|
# If you wish to utilize ReactOnRailsPro production bundle caching logic, then use
|
@@ -95,6 +104,11 @@ ReactOnRails.configure do |config|
|
|
95
104
|
# If you are hashing this file (supposing you are using the same file for client rendering), then
|
96
105
|
# you should include a name that matches your bundle name in your webpack config.
|
97
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
|
98
112
|
|
99
113
|
# THE BELOW OPTIONS FOR SERVER-SIDE RENDERING RARELY NEED CHANGING
|
100
114
|
#
|
@@ -154,14 +168,19 @@ ReactOnRails.configure do |config|
|
|
154
168
|
################################################################################
|
155
169
|
################################################################################
|
156
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.
|
157
174
|
################################################################################
|
158
175
|
# components_subdirectory is the name of the subdirectory matched to detect and register components automatically
|
159
176
|
# The default is nil. You can enable the feature by updating it in the next line.
|
160
|
-
config.components_subdirectory =
|
177
|
+
config.components_subdirectory = nil
|
178
|
+
# Change to a value like this example to enable this feature
|
179
|
+
# config.components_subdirectory = "ror_components"
|
161
180
|
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
181
|
+
# Default configuration to auto loading bundles for components.
|
182
|
+
# default is false. The default can be overrident 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.
|
165
184
|
config.auto_load_bundle = false
|
166
185
|
|
167
186
|
################################################################################
|
@@ -184,20 +203,6 @@ ReactOnRails.configure do |config|
|
|
184
203
|
# The default format is json
|
185
204
|
config.i18n_output_format = 'json'
|
186
205
|
|
187
|
-
################################################################################
|
188
|
-
################################################################################
|
189
|
-
# CLIENT RENDERING OPTIONS
|
190
|
-
# Below options can be overridden by passing options to the react_on_rails
|
191
|
-
# `render_component` view helper method.
|
192
|
-
################################################################################
|
193
|
-
# default is false
|
194
|
-
config.prerender = false
|
195
|
-
|
196
|
-
# You can optionally add values to your rails_context. This object is passed
|
197
|
-
# every time a component renders.
|
198
|
-
# See below for an example definition of RenderingExtension
|
199
|
-
config.rendering_extension = RenderingExtension
|
200
|
-
|
201
206
|
################################################################################
|
202
207
|
################################################################################
|
203
208
|
# TEST CONFIGURATION OPTIONS
|
@@ -180,6 +180,8 @@ The default value of the `auto_load_bundle` parameter can be specified by settin
|
|
180
180
|
|
181
181
|
If server rendering is enabled, the component will be registered for usage both in server and client rendering. In order to have separate definitions for client and server rendering, name the component files as `ComponentName.server.jsx` and `ComponentName.client.jsx`. The `ComponentName.server.jsx` file will be used for server rendering and the `ComponentName.client.jsx` file for client rendering. If you don't want the component rendered on the server, you should only have the `ComponentName.client.jsx` file.
|
182
182
|
|
183
|
+
Once generated, all server entrypoints will be imported into a file named `[ReactOnRails.configuration.server_bundle_js_file]-generated.js`, which in turn will be imported into a source file named the same as `ReactOnRails.configuration.server_bundle_js_file`. If your server bundling logic is such that your server bundle source entrypoint is not named the same as your `ReactOnRails.configuration.server_bundle_js_file` & changing it would be difficult, please let us know.
|
184
|
+
|
183
185
|
*Note: If specifying separate definitions for client and server rendering, please make sure to delete the generalized `ComponentName.jsx` file.*
|
184
186
|
|
185
187
|
### Using Automated Bundle Generation Feature with already defined packs
|
@@ -7,48 +7,46 @@
|
|
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 `package.json` file.
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem "react_on_rails", "
|
11
|
-
gem "
|
10
|
+
gem "react_on_rails", "13.1.0" # Use the latest and the exact version
|
11
|
+
gem "shakapacker", "6.5.4"
|
12
12
|
```
|
13
13
|
|
14
|
-
|
15
|
-
_Use the latest version for react_on_rails._
|
14
|
+
Or use `bundle add`:
|
16
15
|
|
17
|
-
```
|
18
|
-
bundle add
|
19
|
-
bundle add
|
20
|
-
```
|
16
|
+
```bash
|
17
|
+
bundle add react_on_rails --version=13.1.0 --strict
|
18
|
+
bundle add shakapacker --strict
|
19
|
+
```
|
21
20
|
|
22
21
|
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).
|
23
22
|
|
24
23
|
```bash
|
25
|
-
|
26
|
-
bundle exec rails webpacker:install:react
|
24
|
+
rails webpacker:install
|
27
25
|
```
|
28
26
|
|
29
27
|
3. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
|
30
28
|
|
31
|
-
4.
|
29
|
+
4. Run the generator with a simple "Hello World" example (more options below):
|
32
30
|
|
33
31
|
```bash
|
34
|
-
|
32
|
+
rails generate react_on_rails:install
|
35
33
|
```
|
36
34
|
|
37
|
-
|
35
|
+
For more information about this generator use `--help` option:
|
38
36
|
|
39
37
|
```bash
|
40
|
-
|
38
|
+
rails generate react_on_rails:install --help
|
41
39
|
```
|
40
|
+
5. Ensure that you have `overmind` or `foreman` installed
|
42
41
|
|
43
|
-
6.
|
44
|
-
|
45
|
-
7. Start your Rails server:
|
42
|
+
6. Start your Rails server:
|
46
43
|
|
47
44
|
```bash
|
48
|
-
|
45
|
+
./bin/dev
|
49
46
|
```
|
47
|
+
Note: `foreman` defaults to PORT 5000 unless you set the value of PORT in your environment. For example, you can `export PORT=3000` to use the Rails default port of 3000. For the hello_world example this is already set.
|
50
48
|
|
51
|
-
|
49
|
+
7. Visit [localhost:3000/hello_world](http://localhost:3000/hello_world).
|
52
50
|
|
53
51
|
## Installation
|
54
52
|
|
@@ -60,7 +58,7 @@ See the [Installation Overview](https://www.shakacode.com/react-on-rails/docs/ad
|
|
60
58
|
All JavaScript in React On Rails is loaded from npm: [react-on-rails](https://www.npmjs.com/package/react-on-rails). To manually install this (you did not use the generator), assuming you have a standard configuration, run this command (assuming you are in the directory where you have your `node_modules`):
|
61
59
|
|
62
60
|
```bash
|
63
|
-
|
61
|
+
yarn add react-on-rails --exact
|
64
62
|
```
|
65
63
|
|
66
64
|
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.
|
data/docs/guides/tutorial.md
CHANGED
@@ -45,25 +45,23 @@ Then we need to create a fresh Rails application as following.
|
|
45
45
|
First be sure to run `rails -v` and check you are using Rails 5.1.3 or above. If you are using an older version of Rails, you'll need to install webpacker with react per the instructions [here](https://github.com/rails/webpacker).
|
46
46
|
|
47
47
|
```bash
|
48
|
-
|
48
|
+
# For Rails 6.x
|
49
|
+
rails new test-react-on-rails --skip-javascript
|
49
50
|
|
50
|
-
#
|
51
|
-
# Skip javascript so will add that next and get the current version
|
52
|
-
# This is for Rails 7
|
51
|
+
# For Rails 7.x
|
53
52
|
rails new test-react-on-rails --skip-turbolinks --skip-javascript
|
54
53
|
|
55
54
|
cd test-react-on-rails
|
56
55
|
```
|
57
56
|
|
58
57
|
## Add the shakapacker and react_on_rails gems
|
59
|
-
|
60
|
-
of both the gem and npm package. In other words, don't use
|
61
|
-
|
62
|
-
|
63
|
-
```
|
64
|
-
gem 'react_on_rails', '13.0.1' # prefer exact gem version to match npm version
|
65
|
-
gem 'shakapacker', '6.4.0' # prefer exact gem version to match npm version
|
58
|
+
We recommend using the latest version of these gems. Otherwise, specify the
|
59
|
+
exact versions of both the gem and npm package. In other words, don't use
|
60
|
+
the `^` or `~` in the version specifications.
|
66
61
|
|
62
|
+
```bash
|
63
|
+
bundle add react_on_rails --strict
|
64
|
+
bundle add shakapacker --strict
|
67
65
|
```
|
68
66
|
|
69
67
|
Note: The latest released React On Rails version is considered stable. Please use the latest
|
@@ -71,32 +69,34 @@ version to ensure you get all the security patches and the best support.
|
|
71
69
|
|
72
70
|
## Run the shakapacker (webpacker) generator
|
73
71
|
|
74
|
-
```
|
72
|
+
```bash
|
75
73
|
bundle exec rails webpacker:install
|
76
74
|
```
|
77
75
|
|
78
|
-
|
76
|
+
Commit all the changes so far to avoid getting errors in the next step.
|
79
77
|
|
78
|
+
```bash
|
79
|
+
git commit -am "Initial commit"
|
80
80
|
```
|
81
|
-
|
82
|
-
|
83
|
-
git add -A
|
84
|
-
git commit -m "Initial commit"
|
85
|
-
```
|
81
|
+
|
82
|
+
Alternatively you can use `--ignore-warnings` in the next step.
|
86
83
|
|
87
84
|
## Run the React on Rails Generator
|
88
85
|
|
89
|
-
|
86
|
+
```bash
|
87
|
+
rails generate react_on_rails:install
|
88
|
+
```
|
89
|
+
|
90
|
+
You will be prompted to approve changes in certain files. Press `enter` to proceed
|
91
|
+
one by one or enter `a` to replace all configuration files required by the project.
|
92
|
+
You can check the diffs before you commit to see what changed.
|
90
93
|
|
91
94
|
Note, using `redux` is no longer recommended as the basic installer uses React Hooks.
|
92
|
-
If you want the redux install
|
95
|
+
If you want the redux install, run:
|
93
96
|
|
97
|
+
```bash
|
98
|
+
rails generate react_on_rails:install --redux
|
94
99
|
```
|
95
|
-
bundle exec rails generate react_on_rails:install
|
96
|
-
```
|
97
|
-
|
98
|
-
Enter `a` to replace all configuration files required by the project. You can check the diffs
|
99
|
-
before you commit to see what changed.
|
100
100
|
|
101
101
|
## Setting up your environment variables
|
102
102
|
|
@@ -108,14 +108,18 @@ EXECJS_RUNTIME=Node
|
|
108
108
|
|
109
109
|
Then run the server with one of the following options:
|
110
110
|
|
111
|
-
## Running
|
112
|
-
```
|
113
|
-
foreman start -f Procfile.dev
|
114
|
-
```
|
111
|
+
## Running the app
|
115
112
|
|
116
|
-
|
113
|
+
### For HMR:
|
114
|
+
|
115
|
+
```bash
|
116
|
+
./bin/dev
|
117
117
|
```
|
118
|
-
|
118
|
+
|
119
|
+
### Without HMR, statically creating the bundles
|
120
|
+
|
121
|
+
```bash
|
122
|
+
./bin/dev-static
|
119
123
|
```
|
120
124
|
|
121
125
|
Visit [http://localhost:3000/hello_world](http://localhost:3000/hello_world) and see your **React On Rails** app running!
|
@@ -144,6 +144,21 @@ module ReactOnRails
|
|
144
144
|
|
145
145
|
<%= javascript_pack_tag 'hello-world-bundle' %>
|
146
146
|
|
147
|
+
- To start Rails server run:
|
148
|
+
|
149
|
+
./bin/dev # Running with HMR
|
150
|
+
|
151
|
+
or
|
152
|
+
|
153
|
+
./bin/dev # Running with statically created bundles, without HMR
|
154
|
+
|
155
|
+
- To server render, change this line app/views/hello_world/index.html.erb to
|
156
|
+
`prerender: true` to see server rendering (right click on page and select "view source").
|
157
|
+
|
158
|
+
<%= react_component("HelloWorldApp", props: @hello_world_props, prerender: true) %>
|
159
|
+
|
160
|
+
Alternative steps to run the app:
|
161
|
+
|
147
162
|
- Run `rails s` to start the Rails server.
|
148
163
|
|
149
164
|
- Run bin/webpacker-dev-server to start the Webpack dev server for compilation of Webpack
|
@@ -152,18 +167,8 @@ module ReactOnRails
|
|
152
167
|
|
153
168
|
- Visit http://localhost:3000/hello_world and see your React On Rails app running!
|
154
169
|
|
155
|
-
- Alternately, run the foreman command to start the rails server and run webpack#{' '}
|
156
|
-
in watch mode.
|
157
|
-
|
158
|
-
foreman start -f Procfile.dev-static
|
159
|
-
|
160
170
|
- To turn on HMR, edit config/webpacker.yml and set HMR to true. Restart the rails server
|
161
171
|
and bin/webpacker-dev-server. Or use Procfile.dev.
|
162
|
-
|
163
|
-
- To server render, change this line app/views/hello_world/index.html.erb to
|
164
|
-
`prerender: true` to see server rendering (right click on page and select "view source").
|
165
|
-
|
166
|
-
<%= react_component("HelloWorldApp", props: @hello_world_props, prerender: true) %>
|
167
172
|
MSG
|
168
173
|
end
|
169
174
|
|