react_on_rails 11.3.0 → 12.0.0.pre.beta.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 +320 -0
- data/.eslintignore +2 -1
- data/.eslintrc +23 -1
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +3 -1
- data/.prettierignore +10 -1
- data/.prettierrc +3 -0
- data/.rubocop.yml +37 -11
- data/.travis.yml +9 -22
- data/CHANGELOG.md +46 -4
- data/CONTRIBUTING.md +60 -71
- data/Gemfile +3 -4
- data/{COMM-LICENSE → REACT-ON-RAILS-PRO-LICENSE} +6 -9
- data/README.md +102 -69
- data/Rakefile +0 -7
- data/SUMMARY.md +7 -11
- data/book.json +5 -5
- data/docs/additional-reading/asset-pipeline.md +8 -16
- 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/api/javascript-api.md +3 -3
- data/docs/api/redux-store-api.md +4 -2
- data/docs/api/view-helpers-api.md +6 -7
- data/docs/basics/configuration.md +60 -57
- data/docs/basics/deployment.md +1 -2
- data/docs/basics/i18n.md +44 -22
- data/docs/basics/installation-into-an-existing-rails-app.md +2 -2
- data/docs/basics/react-server-rendering.md +1 -1
- data/docs/basics/{generator-functions-and-railscontext.md → render-functions-and-railscontext.md} +59 -21
- data/docs/basics/upgrading-react-on-rails.md +50 -2
- data/docs/basics/webpack-configuration.md +15 -1
- 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 +12 -8
- data/docs/{additional-reading → outdated}/heroku-deployment.md +0 -6
- data/docs/{basics → outdated}/how-react-on-rails-works.md +2 -2
- 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 +4 -7
- data/docs/{misc → outdated}/rails3.md +0 -0
- data/docs/tutorial.md +54 -34
- data/jest.config.js +4 -0
- data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
- data/lib/generators/react_on_rails/generator_helper.rb +4 -6
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +9 -8
- 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.rb +3 -1
- data/lib/react_on_rails/configuration.rb +13 -22
- data/lib/react_on_rails/error.rb +2 -0
- data/lib/react_on_rails/helper.rb +41 -91
- data/lib/react_on_rails/json_parse_error.rb +2 -0
- data/lib/react_on_rails/locales/base.rb +142 -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/server_rendering_pool/ruby_embedded_java_script.rb +41 -46
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +7 -8
- data/lib/react_on_rails/utils.rb +14 -19
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/version_checker.rb +1 -0
- data/lib/react_on_rails/webpacker_utils.rb +13 -2
- data/lib/tasks/assets.rake +5 -45
- data/lib/tasks/locale.rake +8 -2
- data/package-scripts.yml +11 -8
- data/package.json +29 -28
- 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/run_rspec.rake +5 -18
- data/react_on_rails.gemspec +3 -5
- data/tsconfig.json +14 -0
- data/webpackConfigLoader.js +3 -2
- data/yarn.lock +4170 -2197
- metadata +30 -56
- data/Gemfile.rails32 +0 -73
- data/docs/additional-reading/babel.md +0 -5
- data/docs/additional-reading/hot-reloading-rails-development-asset-pipeline.md +0 -47
- data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
- data/lib/react_on_rails/assets_precompile.rb +0 -153
- data/lib/react_on_rails/locales_to_js.rb +0 -138
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: react_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 12.0.0.pre.beta.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '2'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '2'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: coveralls
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,20 +220,6 @@ dependencies:
|
|
220
220
|
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0'
|
223
|
-
- !ruby/object:Gem::Dependency
|
224
|
-
name: pry-stack_explorer
|
225
|
-
requirement: !ruby/object:Gem::Requirement
|
226
|
-
requirements:
|
227
|
-
- - ">="
|
228
|
-
- !ruby/object:Gem::Version
|
229
|
-
version: '0'
|
230
|
-
type: :development
|
231
|
-
prerelease: false
|
232
|
-
version_requirements: !ruby/object:Gem::Requirement
|
233
|
-
requirements:
|
234
|
-
- - ">="
|
235
|
-
- !ruby/object:Gem::Version
|
236
|
-
version: '0'
|
237
223
|
- !ruby/object:Gem::Dependency
|
238
224
|
name: pry-state
|
239
225
|
requirement: !ruby/object:Gem::Requirement
|
@@ -248,20 +234,6 @@ dependencies:
|
|
248
234
|
- - ">="
|
249
235
|
- !ruby/object:Gem::Version
|
250
236
|
version: '0'
|
251
|
-
- !ruby/object:Gem::Dependency
|
252
|
-
name: pry-toys
|
253
|
-
requirement: !ruby/object:Gem::Requirement
|
254
|
-
requirements:
|
255
|
-
- - ">="
|
256
|
-
- !ruby/object:Gem::Version
|
257
|
-
version: '0'
|
258
|
-
type: :development
|
259
|
-
prerelease: false
|
260
|
-
version_requirements: !ruby/object:Gem::Requirement
|
261
|
-
requirements:
|
262
|
-
- - ">="
|
263
|
-
- !ruby/object:Gem::Version
|
264
|
-
version: '0'
|
265
237
|
- !ruby/object:Gem::Dependency
|
266
238
|
name: rails
|
267
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -308,16 +280,16 @@ dependencies:
|
|
308
280
|
name: rubocop
|
309
281
|
requirement: !ruby/object:Gem::Requirement
|
310
282
|
requirements:
|
311
|
-
- -
|
283
|
+
- - '='
|
312
284
|
- !ruby/object:Gem::Version
|
313
|
-
version: 0.
|
285
|
+
version: 0.85.0
|
314
286
|
type: :development
|
315
287
|
prerelease: false
|
316
288
|
version_requirements: !ruby/object:Gem::Requirement
|
317
289
|
requirements:
|
318
|
-
- -
|
290
|
+
- - '='
|
319
291
|
- !ruby/object:Gem::Version
|
320
|
-
version: 0.
|
292
|
+
version: 0.85.0
|
321
293
|
description: See README.md
|
322
294
|
email:
|
323
295
|
- justin@shakacode.com
|
@@ -326,10 +298,12 @@ extensions: []
|
|
326
298
|
extra_rdoc_files: []
|
327
299
|
files:
|
328
300
|
- ".bookignore"
|
301
|
+
- ".circleci/config.yml"
|
329
302
|
- ".coveralls.yml"
|
330
303
|
- ".dockerignore"
|
331
304
|
- ".eslintignore"
|
332
305
|
- ".eslintrc"
|
306
|
+
- ".github/FUNDING.yml"
|
333
307
|
- ".gitignore"
|
334
308
|
- ".npmignore"
|
335
309
|
- ".prettierignore"
|
@@ -340,15 +314,14 @@ files:
|
|
340
314
|
- ".scss-lint.yml"
|
341
315
|
- ".travis.yml"
|
342
316
|
- CHANGELOG.md
|
343
|
-
- COMM-LICENSE
|
344
317
|
- CONTRIBUTING.md
|
345
318
|
- Dockerfile_tests
|
346
319
|
- Gemfile
|
347
|
-
- Gemfile.rails32
|
348
320
|
- KUDOS.md
|
349
321
|
- LICENSE.md
|
350
322
|
- NEWS.md
|
351
323
|
- PROJECTS.md
|
324
|
+
- REACT-ON-RAILS-PRO-LICENSE
|
352
325
|
- README.md
|
353
326
|
- Rakefile
|
354
327
|
- SUMMARY.md
|
@@ -357,17 +330,13 @@ files:
|
|
357
330
|
- docker-compose.yml
|
358
331
|
- docs/additional-reading/angular-js-integration-migration.md
|
359
332
|
- docs/additional-reading/asset-pipeline.md
|
360
|
-
- docs/additional-reading/babel.md
|
361
333
|
- docs/additional-reading/capistrano-deployment.md
|
362
334
|
- docs/additional-reading/convert-rails-5-api-only-app.md
|
363
335
|
- docs/additional-reading/credits.md
|
364
336
|
- docs/additional-reading/elastic-beanstalk.md
|
365
337
|
- docs/additional-reading/foreman-issues.md
|
366
|
-
- docs/additional-reading/heroku-deployment.md
|
367
|
-
- docs/additional-reading/hot-reloading-rails-development-asset-pipeline.md
|
368
338
|
- docs/additional-reading/images.md
|
369
339
|
- docs/additional-reading/node-dependencies-and-npm.md
|
370
|
-
- docs/additional-reading/rails-assets-relative-paths.md
|
371
340
|
- docs/additional-reading/rails-engine-integration.md
|
372
341
|
- docs/additional-reading/rails_view_rendering_from_inline_javascript.md
|
373
342
|
- docs/additional-reading/react-and-redux.md
|
@@ -384,38 +353,42 @@ files:
|
|
384
353
|
- docs/additional-reading/webpack.md
|
385
354
|
- docs/api/javascript-api.md
|
386
355
|
- docs/api/redux-store-api.md
|
387
|
-
- docs/api/ruby-api-hot-reload-view-helpers.md
|
388
356
|
- docs/api/view-helpers-api.md
|
389
357
|
- docs/articles.md
|
390
358
|
- docs/basics/client-vs-server-rendering.md
|
391
359
|
- docs/basics/configuration.md
|
392
360
|
- docs/basics/deployment.md
|
393
361
|
- docs/basics/generator-details.md
|
394
|
-
- docs/basics/generator-functions-and-railscontext.md
|
395
|
-
- docs/basics/how-react-on-rails-works.md
|
396
362
|
- docs/basics/i18n.md
|
397
363
|
- docs/basics/installation-into-an-existing-rails-app.md
|
398
364
|
- docs/basics/migrating-from-react-rails.md
|
399
365
|
- docs/basics/minitest-configuration.md
|
400
366
|
- docs/basics/react-server-rendering.md
|
401
367
|
- docs/basics/recommended-project-structure.md
|
368
|
+
- docs/basics/render-functions-and-railscontext.md
|
402
369
|
- docs/basics/rspec-configuration.md
|
403
370
|
- docs/basics/upgrading-react-on-rails.md
|
404
371
|
- docs/basics/webpack-configuration.md
|
405
372
|
- docs/coding-style/style.md
|
373
|
+
- docs/contributor-info/errors-with-hooks.md
|
406
374
|
- docs/contributor-info/generator-testing.md
|
407
375
|
- docs/contributor-info/linters.md
|
376
|
+
- docs/contributor-info/pull-requests.md
|
408
377
|
- docs/contributor-info/releasing.md
|
409
|
-
- docs/misc-pending/code-splitting.md
|
410
|
-
- docs/misc-pending/manual-installation-overview.md
|
411
|
-
- docs/misc-pending/rails-assets.md
|
412
378
|
- docs/misc/code_of_conduct.md
|
413
379
|
- docs/misc/doctrine.md
|
414
|
-
- docs/
|
380
|
+
- docs/outdated/code-splitting.md
|
381
|
+
- docs/outdated/heroku-deployment.md
|
382
|
+
- docs/outdated/how-react-on-rails-works.md
|
383
|
+
- docs/outdated/manual-installation-overview.md
|
384
|
+
- docs/outdated/rails-assets-relative-paths.md
|
385
|
+
- docs/outdated/rails-assets.md
|
386
|
+
- docs/outdated/rails3.md
|
415
387
|
- docs/testimonials/hvmn.md
|
416
388
|
- docs/testimonials/resortpass.md
|
417
389
|
- docs/testimonials/testimonials.md
|
418
390
|
- docs/tutorial.md
|
391
|
+
- jest.config.js
|
419
392
|
- lib/generators/USAGE
|
420
393
|
- lib/generators/react_on_rails/base_generator.rb
|
421
394
|
- lib/generators/react_on_rails/dev_tests_generator.rb
|
@@ -447,7 +420,6 @@ files:
|
|
447
420
|
- lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.jsx
|
448
421
|
- lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js
|
449
422
|
- lib/react_on_rails.rb
|
450
|
-
- lib/react_on_rails/assets_precompile.rb
|
451
423
|
- lib/react_on_rails/configuration.rb
|
452
424
|
- lib/react_on_rails/controller.rb
|
453
425
|
- lib/react_on_rails/engine.rb
|
@@ -456,7 +428,9 @@ files:
|
|
456
428
|
- lib/react_on_rails/helper.rb
|
457
429
|
- lib/react_on_rails/json_output.rb
|
458
430
|
- lib/react_on_rails/json_parse_error.rb
|
459
|
-
- lib/react_on_rails/
|
431
|
+
- lib/react_on_rails/locales/base.rb
|
432
|
+
- lib/react_on_rails/locales/to_js.rb
|
433
|
+
- lib/react_on_rails/locales/to_json.rb
|
460
434
|
- lib/react_on_rails/prerender_error.rb
|
461
435
|
- lib/react_on_rails/react_component/render_options.rb
|
462
436
|
- lib/react_on_rails/server_rendering_js_code.rb
|
@@ -491,6 +465,7 @@ files:
|
|
491
465
|
- script/release
|
492
466
|
- script/setup
|
493
467
|
- script/test
|
468
|
+
- tsconfig.json
|
494
469
|
- webpackConfigLoader.js
|
495
470
|
- yarn.lock
|
496
471
|
homepage: https://github.com/shakacode/react_on_rails
|
@@ -510,15 +485,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
510
485
|
requirements:
|
511
486
|
- - ">="
|
512
487
|
- !ruby/object:Gem::Version
|
513
|
-
version: 2.
|
488
|
+
version: 2.5.0
|
514
489
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
515
490
|
requirements:
|
516
|
-
- - "
|
491
|
+
- - ">"
|
517
492
|
- !ruby/object:Gem::Version
|
518
|
-
version:
|
493
|
+
version: 1.3.1
|
519
494
|
requirements: []
|
520
|
-
|
521
|
-
rubygems_version: 2.7.9
|
495
|
+
rubygems_version: 3.0.8
|
522
496
|
signing_key:
|
523
497
|
specification_version: 4
|
524
498
|
summary: Rails with react server rendering with webpack.
|
data/Gemfile.rails32
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
eval_gemfile File.expand_path("../react_on_rails.gemspec", __FILE__)
|
6
|
-
|
7
|
-
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
8
|
-
gem "rails", "~> 3.2"
|
9
|
-
# Use sqlite3 as the database for Active Record
|
10
|
-
gem "sqlite3"
|
11
|
-
# Use SCSS for stylesheets
|
12
|
-
gem "sass-rails"
|
13
|
-
# Use Uglifier as compressor for JavaScript assets
|
14
|
-
gem "uglifier"
|
15
|
-
# Use CoffeeScript for .coffee assets and views
|
16
|
-
gem "coffee-rails"
|
17
|
-
|
18
|
-
# Use jquery as the JavaScript library
|
19
|
-
gem "jquery-rails"
|
20
|
-
|
21
|
-
gem "puma"
|
22
|
-
|
23
|
-
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
24
|
-
gem "jbuilder"
|
25
|
-
# bundle exec rake doc:rails generates the API under doc/api.
|
26
|
-
gem "sdoc", group: :doc
|
27
|
-
|
28
|
-
# Use ActiveModel has_secure_password
|
29
|
-
# gem 'bcrypt', '~> 3.1.7'
|
30
|
-
|
31
|
-
# Use Unicorn as the app server
|
32
|
-
# gem 'unicorn'
|
33
|
-
|
34
|
-
# Use Capistrano for deployment
|
35
|
-
# gem 'capistrano-rails', group: :development
|
36
|
-
|
37
|
-
gem "mini_racer"
|
38
|
-
gem "connection_pool"
|
39
|
-
gem "rainbow"
|
40
|
-
gem "addressable"
|
41
|
-
gem "execjs"
|
42
|
-
|
43
|
-
group :development, :test do
|
44
|
-
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
45
|
-
gem "awesome_print"
|
46
|
-
gem "listen"
|
47
|
-
gem "pry"
|
48
|
-
gem "pry-byebug"
|
49
|
-
gem "pry-doc"
|
50
|
-
gem "pry-rails"
|
51
|
-
gem "pry-rescue"
|
52
|
-
gem "pry-stack_explorer"
|
53
|
-
gem "rubocop", require: false
|
54
|
-
gem "ruby-lint", require: false
|
55
|
-
gem "scss_lint", require: false
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
group :test do
|
60
|
-
gem "capybara"
|
61
|
-
gem "capybara-screenshot"
|
62
|
-
gem "coveralls", require: false
|
63
|
-
# install trouble with updated
|
64
|
-
# gem "capybara-webkit"
|
65
|
-
gem "chromedriver-helper"
|
66
|
-
gem "generator_spec"
|
67
|
-
gem "launchy"
|
68
|
-
gem "rspec-rails"
|
69
|
-
gem "rspec-retry"
|
70
|
-
gem "selenium-webdriver"
|
71
|
-
gem 'test-unit', '~> 3.0'
|
72
|
-
gem "equivalent-xml", github: "mbklein/equivalent-xml"
|
73
|
-
end
|
@@ -1,5 +0,0 @@
|
|
1
|
-
# Babel
|
2
|
-
|
3
|
-
As of React on Rails 2.0, we recommend Babel 6 and at least node version 5.5. If you want to stick with Babel 5 for a bit, see [Issue #238](https://github.com/shakacode/react_on_rails/issues/238).
|
4
|
-
|
5
|
-
We recommend that you take a look at https://github.com/shakacode/react-webpack-rails-tutorial and follow the recipe there. We will try to keep that simple example updated.
|
@@ -1,47 +0,0 @@
|
|
1
|
-
*This document should only be referenced if you're **NOT** using the current technique of the rails/webpacker helpers to place your client-side assets in your `/public` directory.*
|
2
|
-
|
3
|
-
|
4
|
-
# Hot Reloading of Assets For Rails Development
|
5
|
-
|
6
|
-
_See [PR #865](https://github.com/shakacode/react_on_rails/pull/865) for a detailed example of doing hot reloading using V8+ with Webpack v2. See [#772](https://github.com/shakacode/react_on_rails/issues/772) and [#361](https://github.com/shakacode/react-webpack-rails-tutorial/issues/361)._
|
7
|
-
|
8
|
-
------
|
9
|
-
|
10
|
-
This document outlines the steps to setup your React On Rails Environment so that you can experience the pleasure of hot reloading of JavaScript and Sass during your Rails development work. See [Issue 332](https://github.com/shakacode/react_on_rails/issues/332) for troubleshooting. There are 3 examples of this setup:
|
11
|
-
|
12
|
-
1. [minimal demo here](https://github.com/retroalgic/react-on-rails-hot-minimal): The most simple and updated hot reloading setup.
|
13
|
-
1. [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy): Simpler setup used for integration testing this gem.
|
14
|
-
1. [shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/). Full featured setup using Twitter bootstrap.
|
15
|
-
|
16
|
-
## Help Wanted
|
17
|
-
|
18
|
-
This doc might be outdated. PRs welcome!
|
19
|
-
|
20
|
-
## High Level Strategy
|
21
|
-
|
22
|
-
We'll use a Webpack Dev server on port 3500 to provide the assets to Rails, rather than the asset pipeline, and only during development mode. This is configured via the `Procfile.hot`.
|
23
|
-
|
24
|
-
`Procfile.static` provides an alternative that uses "static" assets, similar to a production deployment.
|
25
|
-
|
26
|
-
## Places to Configure (Files to Examine)
|
27
|
-
|
28
|
-
1. See the Webpack config files. Note, these examples are now setup for using [CSS Modules](https://github.com/css-modules/css-modules).
|
29
|
-
1. [client/webpack.client.base.config.js](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/webpack.client.base.config.js): Common configuration for hot or static assets.
|
30
|
-
1. [client/webpack.client.rails.hot.config.js](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/webpack.client.rails.hot.config.js): Setup for hot loading, using react-transform-hmr.
|
31
|
-
1. [client/webpack.client.rails.build.config.js](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/webpack.client.rails.build.config.js): Setup for static loading, as is done in a production deployment.
|
32
|
-
1. [app/views/layouts/application.html.erb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/views/layouts/application.html.erb): Uses the view helpers `env_stylesheet_link_tag` and `env_javascript_include_tag` which will either do the hot reloading or the static loading.
|
33
|
-
1. See the Procfiles: [Procfile.hot](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/Procfile.hot) and [Procfile.static](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/Procfile.static). These:
|
34
|
-
1. Start the webpack processes, depending on the mode or HOT or not.
|
35
|
-
2. Start the rails server, setting an ENV value of REACT_ON_RAILS_ENV to HOT if we're hot loading or else setting this to blank.
|
36
|
-
1. Configure the file Rails asset pipeline files:
|
37
|
-
1. [app/assets/javascripts/application_static.js](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/assets/javascripts/application_static.js)
|
38
|
-
1. [app/assets/stylesheets/application_non_webpack.scss](https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/app/assets/stylesheets/application_non_webpack.scss)
|
39
|
-
1. Copy the [client/server-rails-hot.js](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/server-rails-hot.js) to the your client directory.
|
40
|
-
1. Copy the scripts in the top level and client level `package.json` files:
|
41
|
-
1. Top Level: [package.json](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/package.json)
|
42
|
-
1. Client Level: [package.json](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/package.json)
|
43
|
-
|
44
|
-
|
45
|
-
## Code Snippets
|
46
|
-
Please refer to the examples linked above in `spec/dummy` as these code samples might be out of date.
|
47
|
-
|
@@ -1,44 +0,0 @@
|
|
1
|
-
## NOTE: These helpers are NOT needed if using webpacker
|
2
|
-
|
3
|
-
## Hot Reloading View Helpers
|
4
|
-
The `env_javascript_include_tag` and `env_stylesheet_link_tag` support the usage of a webpack dev server for providing the JS and CSS assets during development mode. See the [shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/) for a working example.
|
5
|
-
|
6
|
-
The key options are `static` and `hot` which specify what you want for static vs. hot. Both of these params are optional, and support either a single value, or an array.
|
7
|
-
|
8
|
-
static vs. hot is picked based on whether `ENV["REACT_ON_RAILS_ENV"] == "HOT"`
|
9
|
-
|
10
|
-
```erb
|
11
|
-
<%= env_stylesheet_link_tag(static: 'application_static',
|
12
|
-
hot: 'application_non_webpack',
|
13
|
-
media: 'all',
|
14
|
-
'data-turbolinks-track' => true) %>
|
15
|
-
|
16
|
-
<!-- These do not use turbolinks, so no data-turbolinks-track -->
|
17
|
-
<!-- This is to load the hot assets. -->
|
18
|
-
|
19
|
-
<!-- Note, you can have multiple files here. It's an array. -->
|
20
|
-
<%= env_javascript_include_tag(hot: ['http://localhost:3500/hello-world-bundle.js]') %>
|
21
|
-
|
22
|
-
<!-- These do use turbolinks -->
|
23
|
-
<%= env_javascript_include_tag(static: 'application_static',
|
24
|
-
hot: 'application_non_webpack',
|
25
|
-
'data-turbolinks-track' => true) %>
|
26
|
-
```
|
27
|
-
|
28
|
-
See application.html.erb for usage example and [application.html.erb](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/app%2Fviews%2Flayouts%2Fapplication.html.erb)
|
29
|
-
|
30
|
-
Helper to set CSS and JS assets depending on if we want static or "hot", which means from the Webpack dev server.
|
31
|
-
|
32
|
-
In this example, `application_non_webpack` is simply a CSS asset pipeline file which includes styles not placed in the webpack build. The same can be said for `application_non_webpack` for JS files. Note, the suffix is not used in the helper calls.
|
33
|
-
|
34
|
-
We don't need styles from the webpack build, as those will come via the JavaScript include tags.
|
35
|
-
|
36
|
-
The key options are `static` and `hot` which specify what you want for static vs. hot. Both of
|
37
|
-
these params are optional, and support either a single value, or an array.
|
38
|
-
|
39
|
-
```erb
|
40
|
-
<%= env_stylesheet_link_tag(static: 'application_static',
|
41
|
-
hot: 'application_non_webpack',
|
42
|
-
media: 'all',
|
43
|
-
'data-turbolinks-track' => true) %>
|
44
|
-
```
|
@@ -1,153 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ReactOnRails
|
4
|
-
class AssetsPrecompile
|
5
|
-
class SymlinkTargetDoesNotExistException < StandardError
|
6
|
-
end
|
7
|
-
|
8
|
-
# Used by the rake task
|
9
|
-
def default_asset_path
|
10
|
-
dir = File.join(Rails.configuration.paths["public"].first,
|
11
|
-
Rails.configuration.assets.prefix)
|
12
|
-
Pathname.new(dir)
|
13
|
-
end
|
14
|
-
|
15
|
-
# assets_path should be a Pathname object
|
16
|
-
def initialize(assets_path: nil,
|
17
|
-
symlink_non_digested_assets_regex: nil,
|
18
|
-
generated_assets_dir: nil)
|
19
|
-
@assets_path = ReactOnRails::Utils.truthy_presence(assets_path) || default_asset_path
|
20
|
-
@symlink_non_digested_assets_regex =
|
21
|
-
ReactOnRails::Utils.truthy_presence(symlink_non_digested_assets_regex) ||
|
22
|
-
ReactOnRails.configuration.symlink_non_digested_assets_regex
|
23
|
-
@generated_assets_dir = ReactOnRails::Utils.truthy_presence(generated_assets_dir) ||
|
24
|
-
ReactOnRails.configuration.generated_assets_dir
|
25
|
-
end
|
26
|
-
|
27
|
-
# target and symlink are relative to the assets directory
|
28
|
-
def symlink_file(target, symlink)
|
29
|
-
target_path = @assets_path.join(target)
|
30
|
-
symlink_path = @assets_path.join(symlink)
|
31
|
-
|
32
|
-
target_exists = File.exist?(target_path)
|
33
|
-
raise SymlinkTargetDoesNotExistException, "Target Path was: #{target_path}" unless target_exists
|
34
|
-
|
35
|
-
if symlink_and_points_to_existing_file?(symlink_path)
|
36
|
-
puts "React On Rails: Digested version of #{symlink} already exists indicating #{target} did not change."
|
37
|
-
return
|
38
|
-
end
|
39
|
-
|
40
|
-
if file_or_symlink_exists_at_path?(symlink_path)
|
41
|
-
puts "React On Rails: Removing existing invalid symlink or file #{symlink_path}"
|
42
|
-
FileUtils.remove_file(symlink_path, true)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Might be like:
|
46
|
-
# "images/5cf5db49df178f9357603f945752a1ef.png":
|
47
|
-
# "images/5cf5db49df178f9357603f945752a1ef-033650e1d6193b70d59bb60e773f47b6d9aefdd56abc7cc.png"
|
48
|
-
# need to cd to directory and then symlink
|
49
|
-
target_sub_path, _divider, target_filename = target.rpartition("/")
|
50
|
-
_symlink_sub_path, _divider, symlink_filename = symlink.rpartition("/")
|
51
|
-
dest_path = File.join(@assets_path, target_sub_path)
|
52
|
-
|
53
|
-
puts "React On Rails: Symlinking \"#{target}\" to \"#{symlink}\""
|
54
|
-
FileUtils.chdir(dest_path) do
|
55
|
-
File.symlink(target_filename, symlink_filename)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def symlink_non_digested_assets
|
60
|
-
# digest ==> means that the file has a unique sha so the browser will load a new copy.
|
61
|
-
# Webpack's CSS extract-text-plugin copies digested asset files over to directory where we put
|
62
|
-
# we deploy the webpack compiled JS file. Since Rails will deploy the image files in this
|
63
|
-
# directory with a digest, then the files are essentially "double-digested" and the CSS
|
64
|
-
# references from webpack's CSS would be invalid. The fix is to symlink the double-digested
|
65
|
-
# file back to the original digested name, and make a similar symlink for the gz version.
|
66
|
-
return unless @symlink_non_digested_assets_regex
|
67
|
-
|
68
|
-
manifest_glob = Dir.glob(@assets_path.join(".sprockets-manifest-*.json")) +
|
69
|
-
Dir.glob(@assets_path.join("manifest-*.json")) +
|
70
|
-
Dir.glob(@assets_path.join("manifest.yml"))
|
71
|
-
if manifest_glob.empty?
|
72
|
-
puts "Warning: React On Rails: expected to find .sprockets-manifest-*.json, manifest-*.json "\
|
73
|
-
"or manifest.yml at #{@assets_path}, but found none. Canceling symlinking tasks."
|
74
|
-
return -1
|
75
|
-
end
|
76
|
-
manifest_path = take_most_recent_manifest_path(manifest_glob)
|
77
|
-
manifest_file = File.new(manifest_path)
|
78
|
-
manifest_data = if File.extname(manifest_file) == ".json"
|
79
|
-
manifest_file_data = File.read(manifest_path)
|
80
|
-
JSON.parse(manifest_file_data)["assets"]
|
81
|
-
else
|
82
|
-
YAML.safe_load(manifest_file)
|
83
|
-
end
|
84
|
-
|
85
|
-
# We realize that we're copying other Rails assets that match the regexp, but this just
|
86
|
-
# means that we'd be exposing the original, undigested names.
|
87
|
-
manifest_data.each do |original_filename, rails_digested_filename|
|
88
|
-
# TODO: we should remove any original_filename that is NOT in the webpack deploy folder.
|
89
|
-
next unless original_filename =~ @symlink_non_digested_assets_regex
|
90
|
-
|
91
|
-
# We're symlinking from the digested filename back to the original filename which has
|
92
|
-
# already been symlinked by Webpack
|
93
|
-
symlink_file(rails_digested_filename, original_filename)
|
94
|
-
|
95
|
-
# We want the gz ones as well if they exist
|
96
|
-
if File.exist?(@assets_path.join("#{rails_digested_filename}.gz"))
|
97
|
-
symlink_file("#{rails_digested_filename}.gz", "#{original_filename}.gz")
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def delete_broken_symlinks
|
103
|
-
Dir.glob(@assets_path.join("*")).each do |filename|
|
104
|
-
next unless File.lstat(filename).symlink?
|
105
|
-
|
106
|
-
begin
|
107
|
-
target = File.readlink(filename)
|
108
|
-
rescue StandardError
|
109
|
-
puts "React on Rails: Warning: your platform doesn't support File::readlink method." \
|
110
|
-
"Skipping broken link check."
|
111
|
-
break
|
112
|
-
end
|
113
|
-
path = Pathname.new(File.dirname(filename))
|
114
|
-
target_path = path.join(target)
|
115
|
-
unless File.exist?(target_path)
|
116
|
-
puts "React on Rails: Deleting broken link: #{filename}"
|
117
|
-
File.delete(filename)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def clobber
|
123
|
-
dir = Rails.root.join(@generated_assets_dir)
|
124
|
-
if dir.present? && File.directory?(dir)
|
125
|
-
puts "Deleting files in directory #{dir}"
|
126
|
-
FileUtils.rm_r(Dir.glob(Rails.root.join("#{@generated_assets_dir}/*")))
|
127
|
-
else
|
128
|
-
puts "Could not find generated_assets_dir #{dir} defined in react_on_rails initializer: "
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
private
|
133
|
-
|
134
|
-
def take_most_recent_manifest_path(manifest_glob)
|
135
|
-
manifest_glob.max_by { |name| File.mtime(name) }
|
136
|
-
end
|
137
|
-
|
138
|
-
def symlink_and_points_to_existing_file?(symlink_path)
|
139
|
-
# File.exist?(symlink_path) will check the file the sym is pointing to is existing
|
140
|
-
# File.lstat(symlink_path).symlink? confirms that this is a symlink
|
141
|
-
File.exist?(symlink_path) && File.lstat(symlink_path).symlink?
|
142
|
-
end
|
143
|
-
|
144
|
-
def file_or_symlink_exists_at_path?(path)
|
145
|
-
# We use lstat and not stat, we we don't want to visit the file that the symlink maybe
|
146
|
-
# pointing to. We can't use File.exist?, as that would check the file pointed at by the symlink.
|
147
|
-
File.lstat(path)
|
148
|
-
true
|
149
|
-
rescue StandardError
|
150
|
-
false
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|