react_on_rails_pro 16.4.0.rc.7 → 16.4.0.rc.8
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/CONTRIBUTING.md +2 -2
- data/Gemfile.lock +3 -3
- data/README.md +16 -16
- data/lib/react_on_rails_pro/concerns/rsc_payload_renderer.rb +3 -1
- data/lib/react_on_rails_pro/version.rb +1 -1
- metadata +4 -35
- data/docs/bundle-caching.md +0 -219
- data/docs/caching.md +0 -246
- data/docs/code-splitting-loadable-components.md +0 -326
- data/docs/configuration.md +0 -165
- data/docs/home-pro.md +0 -164
- data/docs/installation.md +0 -328
- data/docs/js-memory-leaks.md +0 -21
- data/docs/node-renderer/basics.md +0 -94
- data/docs/node-renderer/debugging.md +0 -42
- data/docs/node-renderer/error-reporting-and-tracing.md +0 -172
- data/docs/node-renderer/heroku.md +0 -101
- data/docs/node-renderer/js-configuration.md +0 -163
- data/docs/node-renderer/troubleshooting.md +0 -5
- data/docs/profiling-server-side-rendering-code.md +0 -180
- data/docs/react-server-components/add-streaming-and-interactivity.md +0 -190
- data/docs/react-server-components/create-without-ssr.md +0 -448
- data/docs/react-server-components/flight-protocol-syntax.md +0 -294
- data/docs/react-server-components/glossary.md +0 -131
- data/docs/react-server-components/how-react-server-components-work.md +0 -250
- data/docs/react-server-components/inside-client-components.md +0 -333
- data/docs/react-server-components/purpose-and-benefits.md +0 -253
- data/docs/react-server-components/rendering-flow.md +0 -90
- data/docs/react-server-components/selective-hydration-in-streamed-components.md +0 -75
- data/docs/react-server-components/server-side-rendering.md +0 -73
- data/docs/react-server-components/tutorial.md +0 -19
- data/docs/release-notes/4.0.md +0 -103
- data/docs/release-notes/v4-react-server-components.md +0 -66
- data/docs/ruby-api.md +0 -9
- data/docs/streaming-server-rendering.md +0 -239
- data/docs/troubleshooting.md +0 -11
- data/docs/updating.md +0 -283
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 717ead6ca9b9c1f7354820f063551a8403cabb9fafeb095bd46f35e3d368a483
|
|
4
|
+
data.tar.gz: 5062b202868b9106090becb6dd5f040761a2dd37ec2a1323053e43df111044ed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2fc8c9ad613776be17f834f8a7c2d7ff07b123e6e703b8dd21ffdc4687ee51d0037b49c813c7f7b9596266bfa15885336b1f6ce9df6530e995c68d58557d745
|
|
7
|
+
data.tar.gz: 025cf054e18a200c61ad22199617ce0374889b1f825290ee13952f02bb993532cf8b1738c0df4a7295c4b9bf576782bf42abe04395f9071dd46b0686697c8c5b
|
data/CONTRIBUTING.md
CHANGED
|
@@ -47,12 +47,12 @@ From [How to Write a Git Commit Message](http://chris.beams.io/posts/git-commit/
|
|
|
47
47
|
## Doc Changes
|
|
48
48
|
|
|
49
49
|
When making doc changes, we want the change to work on both [the ShakaCode docs site](https://www.shakacode.com/react-on-rails-pro/docs/) and when browsing the GitHub repo.
|
|
50
|
-
The issue is that the
|
|
50
|
+
The issue is that the ShakaCode site is generated only from files in [`../docs/pro`](../docs/pro), so any references from them to non-doc files must use the full GitHub URL.
|
|
51
51
|
|
|
52
52
|
### Links to other docs:
|
|
53
53
|
|
|
54
54
|
- When making references to doc files, use a relative URL path like:
|
|
55
|
-
`[Installation
|
|
55
|
+
`[Installation Guide](../docs/pro/installation.md)`
|
|
56
56
|
|
|
57
57
|
- When making references to source code files, use a full url path like:
|
|
58
58
|
`[spec/dummy/config/initializers/react_on_rails.rb](https://github.com/shakacode/react_on_rails/tree/master/react_on_rails_pro/spec/dummy/config/initializers/react_on_rails.rb)`
|
data/Gemfile.lock
CHANGED
|
@@ -9,7 +9,7 @@ GIT
|
|
|
9
9
|
PATH
|
|
10
10
|
remote: ..
|
|
11
11
|
specs:
|
|
12
|
-
react_on_rails (16.4.0.rc.
|
|
12
|
+
react_on_rails (16.4.0.rc.8)
|
|
13
13
|
addressable
|
|
14
14
|
connection_pool
|
|
15
15
|
execjs (~> 2.5)
|
|
@@ -20,7 +20,7 @@ PATH
|
|
|
20
20
|
PATH
|
|
21
21
|
remote: .
|
|
22
22
|
specs:
|
|
23
|
-
react_on_rails_pro (16.4.0.rc.
|
|
23
|
+
react_on_rails_pro (16.4.0.rc.8)
|
|
24
24
|
addressable
|
|
25
25
|
async (>= 2.6)
|
|
26
26
|
connection_pool
|
|
@@ -29,7 +29,7 @@ PATH
|
|
|
29
29
|
httpx (~> 1.5)
|
|
30
30
|
jwt (~> 2.7)
|
|
31
31
|
rainbow
|
|
32
|
-
react_on_rails (= 16.4.0.rc.
|
|
32
|
+
react_on_rails (= 16.4.0.rc.8)
|
|
33
33
|
|
|
34
34
|
GEM
|
|
35
35
|
remote: https://rubygems.org/
|
data/README.md
CHANGED
|
@@ -156,7 +156,7 @@ end %>
|
|
|
156
156
|
- Automatic cache invalidation based on props
|
|
157
157
|
- Works with Rails fragment caching infrastructure
|
|
158
158
|
|
|
159
|
-
**📖 Learn more**: [docs/caching.md](
|
|
159
|
+
**📖 Learn more**: [docs/pro/caching.md](../docs/pro/caching.md)
|
|
160
160
|
|
|
161
161
|
### 2. Prerender Caching
|
|
162
162
|
|
|
@@ -175,7 +175,7 @@ end
|
|
|
175
175
|
- Caches across multiple requests
|
|
176
176
|
- Complements fragment caching for maximum performance
|
|
177
177
|
|
|
178
|
-
**📖 Learn more**: [docs/caching.md](
|
|
178
|
+
**📖 Learn more**: [docs/pro/caching.md](../docs/pro/caching.md)
|
|
179
179
|
|
|
180
180
|
### 3. React on Rails Pro Node Renderer
|
|
181
181
|
|
|
@@ -203,7 +203,7 @@ reactOnRailsProNodeRenderer({
|
|
|
203
203
|
});
|
|
204
204
|
```
|
|
205
205
|
|
|
206
|
-
**📖 Learn more**: [docs/node-renderer/basics.md](
|
|
206
|
+
**📖 Learn more**: [docs/pro/node-renderer/basics.md](../docs/pro/node-renderer/basics.md)
|
|
207
207
|
|
|
208
208
|
### 4. React Server Components (RSC)
|
|
209
209
|
|
|
@@ -236,7 +236,7 @@ Speed up webpack rebuilds by caching unchanged bundles.
|
|
|
236
236
|
- **Faster development**: Hot reload only what changed
|
|
237
237
|
- **Lower costs**: Reduce build server time
|
|
238
238
|
|
|
239
|
-
**📖 Learn more**: [docs/bundle-caching.md](
|
|
239
|
+
**📖 Learn more**: [docs/pro/bundle-caching.md](../docs/pro/bundle-caching.md)
|
|
240
240
|
|
|
241
241
|
### 6. Global State Management
|
|
242
242
|
|
|
@@ -249,7 +249,7 @@ ReactOnRailsPro.configure do |config|
|
|
|
249
249
|
end
|
|
250
250
|
```
|
|
251
251
|
|
|
252
|
-
**📖 Learn more**: [docs/configuration.md](
|
|
252
|
+
**📖 Learn more**: [docs/pro/configuration.md](../docs/pro/configuration.md)
|
|
253
253
|
|
|
254
254
|
---
|
|
255
255
|
|
|
@@ -326,9 +326,9 @@ rails console
|
|
|
326
326
|
|
|
327
327
|
### Next Steps
|
|
328
328
|
|
|
329
|
-
- **Enable caching**: See [docs/caching.md](
|
|
330
|
-
- **Set up Node Renderer**: See [docs/node-renderer/basics.md](
|
|
331
|
-
- **Optimize performance**: See [docs/configuration.md](
|
|
329
|
+
- **Enable caching**: See [docs/pro/caching.md](../docs/pro/caching.md)
|
|
330
|
+
- **Set up Node Renderer**: See [docs/pro/node-renderer/basics.md](../docs/pro/node-renderer/basics.md)
|
|
331
|
+
- **Optimize performance**: See [docs/pro/configuration.md](../docs/pro/configuration.md)
|
|
332
332
|
- **Set up for your team**: See [LICENSE_SETUP.md](./LICENSE_SETUP.md#team-setup)
|
|
333
333
|
|
|
334
334
|
---
|
|
@@ -337,20 +337,20 @@ rails console
|
|
|
337
337
|
|
|
338
338
|
### Installation & Setup
|
|
339
339
|
|
|
340
|
-
- **[Installation Guide](
|
|
340
|
+
- **[Installation Guide](../docs/pro/installation.md)** - Detailed installation instructions
|
|
341
341
|
- **[License Setup](./LICENSE_SETUP.md)** - Complete license configuration guide
|
|
342
|
-
- **[Configuration Reference](
|
|
342
|
+
- **[Configuration Reference](../docs/pro/configuration.md)** - All configuration options
|
|
343
343
|
|
|
344
344
|
### Features
|
|
345
345
|
|
|
346
|
-
- **[Caching Guide](
|
|
347
|
-
- **[Bundle Caching](
|
|
348
|
-
- **[Node Renderer Basics](
|
|
349
|
-
- **[Node Renderer Configuration](
|
|
346
|
+
- **[Caching Guide](../docs/pro/caching.md)** - Fragment and prerender caching
|
|
347
|
+
- **[Bundle Caching](../docs/pro/bundle-caching.md)** - Speed up webpack builds
|
|
348
|
+
- **[Node Renderer Basics](../docs/pro/node-renderer/basics.md)** - Standalone Node.js server
|
|
349
|
+
- **[Node Renderer Configuration](../docs/pro/node-renderer/js-configuration.md)** - JavaScript config
|
|
350
350
|
|
|
351
351
|
### API Reference
|
|
352
352
|
|
|
353
|
-
- **[Ruby API](
|
|
353
|
+
- **[Ruby API](../docs/pro/ruby-api.md)** - Helper methods and utilities
|
|
354
354
|
- **[CHANGELOG](./CHANGELOG.md)** - Version history and upgrade notes
|
|
355
355
|
|
|
356
356
|
### Upgrading
|
|
@@ -408,7 +408,7 @@ Check out these production applications using React on Rails Pro:
|
|
|
408
408
|
|
|
409
409
|
- **📧 Email Support**: [support@shakacode.com](mailto:support@shakacode.com)
|
|
410
410
|
- **💼 Sales & Licensing**: [justin@shakacode.com](mailto:justin@shakacode.com)
|
|
411
|
-
- **📖 Documentation**: [docs/](
|
|
411
|
+
- **📖 Documentation**: [docs/pro/](../docs/pro/)
|
|
412
412
|
- **🐛 Found a Bug?**: Email [support@shakacode.com](mailto:support@shakacode.com) (for Pro customers)
|
|
413
413
|
|
|
414
414
|
### Professional Services
|
|
@@ -27,7 +27,9 @@ module ReactOnRailsPro
|
|
|
27
27
|
"[React on Rails Pro] RSC payload templates are now rendered with format :text. " \
|
|
28
28
|
"If you override `custom_rsc_payload_template`, make sure the override resolves to " \
|
|
29
29
|
"a text or format-neutral template (for example `rsc_payload.text.erb`) instead of " \
|
|
30
|
-
"only `.html.erb`. See
|
|
30
|
+
"only `.html.erb`. See\n" \
|
|
31
|
+
"https://github.com/shakacode/react_on_rails/blob/master/docs/pro/updating.md " \
|
|
32
|
+
"for upgrade notes.\n\n" \
|
|
31
33
|
"Original error: #{e.message}"
|
|
32
34
|
)
|
|
33
35
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: react_on_rails_pro
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 16.4.0.rc.
|
|
4
|
+
version: 16.4.0.rc.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Gordon
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-03-
|
|
11
|
+
date: 2026-03-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: addressable
|
|
@@ -128,14 +128,14 @@ dependencies:
|
|
|
128
128
|
requirements:
|
|
129
129
|
- - '='
|
|
130
130
|
- !ruby/object:Gem::Version
|
|
131
|
-
version: 16.4.0.rc.
|
|
131
|
+
version: 16.4.0.rc.8
|
|
132
132
|
type: :runtime
|
|
133
133
|
prerelease: false
|
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
|
135
135
|
requirements:
|
|
136
136
|
- - '='
|
|
137
137
|
- !ruby/object:Gem::Version
|
|
138
|
-
version: 16.4.0.rc.
|
|
138
|
+
version: 16.4.0.rc.8
|
|
139
139
|
- !ruby/object:Gem::Dependency
|
|
140
140
|
name: bundler
|
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -225,37 +225,6 @@ files:
|
|
|
225
225
|
- app/helpers/react_on_rails_pro_helper.rb
|
|
226
226
|
- app/views/react_on_rails_pro/rsc_payload.text.erb
|
|
227
227
|
- babel.config.js
|
|
228
|
-
- docs/bundle-caching.md
|
|
229
|
-
- docs/caching.md
|
|
230
|
-
- docs/code-splitting-loadable-components.md
|
|
231
|
-
- docs/configuration.md
|
|
232
|
-
- docs/home-pro.md
|
|
233
|
-
- docs/installation.md
|
|
234
|
-
- docs/js-memory-leaks.md
|
|
235
|
-
- docs/node-renderer/basics.md
|
|
236
|
-
- docs/node-renderer/debugging.md
|
|
237
|
-
- docs/node-renderer/error-reporting-and-tracing.md
|
|
238
|
-
- docs/node-renderer/heroku.md
|
|
239
|
-
- docs/node-renderer/js-configuration.md
|
|
240
|
-
- docs/node-renderer/troubleshooting.md
|
|
241
|
-
- docs/profiling-server-side-rendering-code.md
|
|
242
|
-
- docs/react-server-components/add-streaming-and-interactivity.md
|
|
243
|
-
- docs/react-server-components/create-without-ssr.md
|
|
244
|
-
- docs/react-server-components/flight-protocol-syntax.md
|
|
245
|
-
- docs/react-server-components/glossary.md
|
|
246
|
-
- docs/react-server-components/how-react-server-components-work.md
|
|
247
|
-
- docs/react-server-components/inside-client-components.md
|
|
248
|
-
- docs/react-server-components/purpose-and-benefits.md
|
|
249
|
-
- docs/react-server-components/rendering-flow.md
|
|
250
|
-
- docs/react-server-components/selective-hydration-in-streamed-components.md
|
|
251
|
-
- docs/react-server-components/server-side-rendering.md
|
|
252
|
-
- docs/react-server-components/tutorial.md
|
|
253
|
-
- docs/release-notes/4.0.md
|
|
254
|
-
- docs/release-notes/v4-react-server-components.md
|
|
255
|
-
- docs/ruby-api.md
|
|
256
|
-
- docs/streaming-server-rendering.md
|
|
257
|
-
- docs/troubleshooting.md
|
|
258
|
-
- docs/updating.md
|
|
259
228
|
- eslint.config.mjs
|
|
260
229
|
- lib/react_on_rails_pro.rb
|
|
261
230
|
- lib/react_on_rails_pro/assets_precompile.rb
|
data/docs/bundle-caching.md
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
# Bundle Caching
|
|
2
|
-
|
|
3
|
-
## Why?
|
|
4
|
-
|
|
5
|
-
Building webpack bundles is often time-consuming, and the same bundles are built many times.
|
|
6
|
-
For example, you might build the production bundles during CI, then for a Review app, then
|
|
7
|
-
for Staging, and maybe even for Production. Or you might want to deploy a small Ruby-only
|
|
8
|
-
change to production, but you will have to wait minutes for your bundles to be built again.
|
|
9
|
-
|
|
10
|
-
## Solution
|
|
11
|
-
|
|
12
|
-
React on Rails 2.1.0 introduces bundle caching based on a digest of all the source files, defined
|
|
13
|
-
in the `config/shakapacker.yml` file, plus other files defined with `config.dependency_globs` and
|
|
14
|
-
excluding any files from `config.excluded_dependency_globs`. Creating this hash key takes at most a
|
|
15
|
-
few seconds for even large projects. Additionally, the cache key includes
|
|
16
|
-
|
|
17
|
-
1. NODE_ENV
|
|
18
|
-
2. Version of React on Rails Pro
|
|
19
|
-
3. Configurable additional env values by supplying an array in method cache_keys on the `remote_bundle_cache_adapter`. See examples below.
|
|
20
|
-
|
|
21
|
-
This cache key is used for saving files to some remote storage, typically S3.
|
|
22
|
-
|
|
23
|
-
## Bonus for local development with multiple directories building production builds
|
|
24
|
-
|
|
25
|
-
Bundle caching can help save time if you have multiple directories for the same repository.
|
|
26
|
-
|
|
27
|
-
The bundles are cached in `Rails.root.join('tmp', 'bundle_cache')`
|
|
28
|
-
|
|
29
|
-
So, if you have sibling directories for the same project, you can make a sym link so both directories use the same bundle cache directory.
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
cd my_project2/tmp
|
|
33
|
-
ln -s ../../my_project/tmp/bundle_cache
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Configuration
|
|
37
|
-
|
|
38
|
-
### 1. React on Rails Configuration
|
|
39
|
-
|
|
40
|
-
First, we need to tell React on Rails to use a custom build module. In
|
|
41
|
-
`config/initializers/react_on_rails`, set this value:
|
|
42
|
-
|
|
43
|
-
```ruby
|
|
44
|
-
config.build_production_command = ReactOnRailsPro::AssetsPrecompile
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Alternatively, if you need to run something after the files are built or extracted from the cache, you can do something like this:
|
|
48
|
-
|
|
49
|
-
```ruby
|
|
50
|
-
ReactOnRails.configure do |config|
|
|
51
|
-
# This configures the script to run to build the production assets by webpack. Set this to nil
|
|
52
|
-
# if you don't want react_on_rails building this file for you.
|
|
53
|
-
config.build_production_command = CustomBuildCommand
|
|
54
|
-
end
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
And define it like this:
|
|
58
|
-
|
|
59
|
-
```ruby
|
|
60
|
-
module CustomBuildCommand
|
|
61
|
-
def self.call
|
|
62
|
-
ReactOnRailsPro::AssetsPrecompile.call
|
|
63
|
-
Rake::Task['react_on_rails_pro:pre_stage_bundle_for_node_renderer'].invoke
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### 2. React on Rails Pro Configuration
|
|
69
|
-
|
|
70
|
-
Next, we need to configure the `config/initializers/react_on_rails_pro.rb` with some module,
|
|
71
|
-
say called S3BundleCacheAdapter.
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
config.remote_bundle_cache_adapter = S3BundleCacheAdapter
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
This module needs four class methods: `cache_keys` (optional), `build`, `fetch`, `upload`. See two
|
|
78
|
-
examples of this below.
|
|
79
|
-
|
|
80
|
-
Also, add whatever file the remote_bundle_cache_adapter module is defined in to `config.dependency_globs`.
|
|
81
|
-
|
|
82
|
-
If there are any other files for which changes should bust the fragment cache for
|
|
83
|
-
cached_react_component and cached_react_component_hash, add those as well to `config.dependency_globs`. This should include any files used to generate the JSON props, webpack and/or Shakapacker configuration files, and package lockfiles.
|
|
84
|
-
|
|
85
|
-
To simplify your configuration, entire directories can be added to `config.dependency_globs` & then any irrelevant files or subdirectories can be added to `config.excluded_dependency_globs`
|
|
86
|
-
|
|
87
|
-
For example:
|
|
88
|
-
|
|
89
|
-
```ruby
|
|
90
|
-
config.dependency_globs = [ File.join(Rails.root, "app", "views", "**", "*.jbuilder") ]
|
|
91
|
-
config.excluded_dependency_globs = [ File.join(Rails.root, "app", "views", "**", "dont_hash_this.jbuilder") ]
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
will hash all files in `app/views` that have the `jbuilder` extension except for any file named `dont_hash_this.jbuilder`.
|
|
95
|
-
|
|
96
|
-
The goal is that Ruby only changes that don't affect your webpack bundles don't change the cache keys, and anything that could affect the bundles MUST change the cache keys!
|
|
97
|
-
|
|
98
|
-
### 3. Remove any call to rake task `react_on_rails_pro:pre_stage_bundle_for_node_renderer`
|
|
99
|
-
|
|
100
|
-
This task is called automatically if you're using bundle caching.
|
|
101
|
-
|
|
102
|
-
```ruby
|
|
103
|
-
Rake::Task['react_on_rails_pro:pre_stage_bundle_for_node_renderer'].invoke
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
#### Custom ENV cache keys
|
|
107
|
-
|
|
108
|
-
Check your webpack config for the webpack.DefinePlugin. That allows JS code to use
|
|
109
|
-
`process.env.MY_ENV_VAR` resulting in bundles that differ depending on the ENV value set.
|
|
110
|
-
|
|
111
|
-
Thus, if you access these `process.env.MY_ENV_VAR` in your JS code, then you need to include such
|
|
112
|
-
ENV vars in return value of the `cache keys` method.
|
|
113
|
-
|
|
114
|
-
A much better approach than accessing `process.env` is to use the
|
|
115
|
-
`config/initializers/react_on_rails.rb` setting for the`config.rendering_extension` to always
|
|
116
|
-
pass some values into the rendering props.
|
|
117
|
-
|
|
118
|
-
See [our railsContext docs](https://www.shakacode.com/react-on-rails/docs/basics/render-functions-and-railscontext/#customization-of-the-railscontext) for more details.
|
|
119
|
-
|
|
120
|
-
Also, if your webpack build process depends on any ENV values, then you will also need to add those
|
|
121
|
-
to return value of the `cache_keys` method.
|
|
122
|
-
|
|
123
|
-
Note, the NODE_ENV value is always included in the cache_keys.
|
|
124
|
-
|
|
125
|
-
Another use of the ENV values would be a cache version, so incrementing this ENV value
|
|
126
|
-
would force a new cache value.
|
|
127
|
-
|
|
128
|
-
## Disabling via an ENV value
|
|
129
|
-
|
|
130
|
-
Once configured for bundle caching, ReactOnRailsPro::AssetsPrecompile's caching functionality
|
|
131
|
-
can be disabled by setting ENV["DISABLE_PRECOMPILE_CACHE"] equal to "true"
|
|
132
|
-
|
|
133
|
-
### Examples of `remote_bundle_cache_adapter`:
|
|
134
|
-
|
|
135
|
-
#### S3BundleCacheAdapter
|
|
136
|
-
|
|
137
|
-
Example of a module for custom methods for the `remote_bundle_cache_adapter`.
|
|
138
|
-
|
|
139
|
-
Note, S3UploadService is your own code that fetches and uploads.
|
|
140
|
-
|
|
141
|
-
```ruby
|
|
142
|
-
class S3BundleCacheAdapter
|
|
143
|
-
# Optional
|
|
144
|
-
# return an Array of Strings that should get added to the cache key.
|
|
145
|
-
# These are values to put in the cache key based on either using the webpack.DefinePlugin
|
|
146
|
-
# or webpack compilation varying by the ENV values.
|
|
147
|
-
# See the use of the webpack.DefinePlugin. That allows JS code to use
|
|
148
|
-
# process.env.MY_ENV_VAR resulting in bundles that differ depending on the ENV value set
|
|
149
|
-
# when building the bundles.
|
|
150
|
-
# Note, NODE_ENV is automatically included in the default cache key.
|
|
151
|
-
# Also, we can have an ENV value be a cache version, so incrementing this ENV value
|
|
152
|
-
# would force a new cache value.
|
|
153
|
-
def self.cache_keys
|
|
154
|
-
[Rails.env, ENV['SOME_ENV_VALUE']]
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
# return value is unused
|
|
158
|
-
# This command should build the bundles
|
|
159
|
-
def self.build
|
|
160
|
-
Rake.sh(ReactOnRails::Utils.prepend_cd_node_modules_directory('yarn start build.prod').to_s)
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
# parameter zipped_bundles_filename will be a string
|
|
164
|
-
# should return the zipped file as a string if successful & nil if not
|
|
165
|
-
def self.fetch(zipped_bundles_filename:)
|
|
166
|
-
result = S3UploadService.new.fetch_object(zipped_bundles_filename)
|
|
167
|
-
result.get.body.read if result
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
# Optional: method to return an array of extra files paths, that require caching.
|
|
171
|
-
# These files get placed at the `extra_files` directory at the top of the zipfile
|
|
172
|
-
# and are moved to the original places after unzipping the bundles.
|
|
173
|
-
def self.extra_files_to_cache
|
|
174
|
-
[ Rails.root.join("app", "javascript", "utils", "operationStore.json") ]
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
# parameter zipped_bundles_filepath will be a Pathname
|
|
178
|
-
# return value is unused
|
|
179
|
-
def self.upload(zipped_bundles_filepath:)
|
|
180
|
-
return unless ENV['UPLOAD_BUNDLES_TO_S3'] == 'true'
|
|
181
|
-
|
|
182
|
-
zipped_bundles_filename = zipped_bundles_filepath.basename.to_s
|
|
183
|
-
puts "Bundles are being uploaded to s3 as #{zipped_bundles_filename}"
|
|
184
|
-
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
185
|
-
S3UploadService.new.upload_object(zipped_bundles_filename,
|
|
186
|
-
File.read(zipped_bundles_filepath, mode: 'rb'),
|
|
187
|
-
'application/zip', expiration_months: 12)
|
|
188
|
-
ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
189
|
-
elapsed = (ending - starting).round(2)
|
|
190
|
-
puts "Bundles uploaded to s3 as #{zipped_bundles_filename} in #{elapsed} seconds"
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
#### LocalBundleCacheAdapter
|
|
196
|
-
|
|
197
|
-
Example of a module for custom methods for the `remote_bundle_cache_adapter` that does not save files
|
|
198
|
-
remotely. Only local files are used.
|
|
199
|
-
|
|
200
|
-
```ruby
|
|
201
|
-
class LocalBundleCacheAdapter
|
|
202
|
-
def self.cache_keys
|
|
203
|
-
# if no additional cache keys, return an empty array
|
|
204
|
-
[]
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
def self.build
|
|
208
|
-
Rake.sh(ReactOnRails::Utils.prepend_cd_node_modules_directory('yarn start build.prod').to_s)
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def self.fetch(zipped_bundles_filename:)
|
|
212
|
-
# no-op
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def self.upload(zipped_bundles_filepath:)
|
|
216
|
-
# no-op
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
```
|