react_on_rails 11.2.1 → 12.0.0.pre.beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +320 -0
  3. data/.eslintignore +2 -1
  4. data/.eslintrc +23 -1
  5. data/.github/FUNDING.yml +1 -0
  6. data/.gitignore +3 -1
  7. data/.prettierignore +10 -1
  8. data/.prettierrc +3 -0
  9. data/.rubocop.yml +37 -11
  10. data/.travis.yml +10 -20
  11. data/CHANGELOG.md +85 -9
  12. data/CONTRIBUTING.md +60 -71
  13. data/Gemfile +3 -4
  14. data/{COMM-LICENSE → REACT-ON-RAILS-PRO-LICENSE} +6 -9
  15. data/README.md +121 -71
  16. data/Rakefile +0 -7
  17. data/SUMMARY.md +9 -12
  18. data/book.json +5 -5
  19. data/docs/additional-reading/asset-pipeline.md +8 -16
  20. data/docs/additional-reading/react-helmet.md +30 -10
  21. data/docs/additional-reading/react-router.md +52 -75
  22. data/docs/additional-reading/server-rendering-tips.md +12 -7
  23. data/docs/api/javascript-api.md +3 -3
  24. data/docs/api/redux-store-api.md +4 -2
  25. data/docs/api/view-helpers-api.md +8 -9
  26. data/docs/basics/configuration.md +68 -59
  27. data/docs/basics/deployment.md +1 -2
  28. data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +49 -0
  29. data/docs/basics/i18n.md +44 -22
  30. data/docs/basics/installation-into-an-existing-rails-app.md +2 -2
  31. data/docs/basics/minitest-configuration.md +31 -0
  32. data/docs/basics/react-server-rendering.md +1 -1
  33. data/docs/basics/{generator-functions-and-railscontext.md → render-functions-and-railscontext.md} +59 -21
  34. data/docs/basics/rspec-configuration.md +29 -17
  35. data/docs/basics/upgrading-react-on-rails.md +67 -3
  36. data/docs/basics/webpack-configuration.md +15 -1
  37. data/docs/contributor-info/errors-with-hooks.md +45 -0
  38. data/docs/contributor-info/pull-requests.md +44 -0
  39. data/docs/misc/doctrine.md +1 -1
  40. data/docs/{misc-pending → outdated}/code-splitting.md +12 -8
  41. data/docs/{additional-reading → outdated}/heroku-deployment.md +0 -6
  42. data/docs/{basics → outdated}/how-react-on-rails-works.md +3 -3
  43. data/docs/{misc-pending → outdated}/manual-installation-overview.md +5 -5
  44. data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +3 -3
  45. data/docs/{misc-pending → outdated}/rails-assets.md +4 -7
  46. data/docs/{misc → outdated}/rails3.md +0 -0
  47. data/docs/testimonials/resortpass.md +13 -0
  48. data/docs/testimonials/testimonials.md +11 -1
  49. data/docs/tutorial.md +96 -70
  50. data/jest.config.js +4 -0
  51. data/lib/generators/react_on_rails/base_generator.rb +2 -2
  52. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  53. data/lib/generators/react_on_rails/generator_helper.rb +4 -6
  54. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +3 -1
  55. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +26 -0
  56. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +20 -40
  57. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +2 -1
  58. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +4 -8
  59. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
  60. data/lib/react_on_rails.rb +3 -1
  61. data/lib/react_on_rails/configuration.rb +13 -22
  62. data/lib/react_on_rails/error.rb +2 -0
  63. data/lib/react_on_rails/helper.rb +100 -143
  64. data/lib/react_on_rails/json_parse_error.rb +2 -0
  65. data/lib/react_on_rails/locales/base.rb +150 -0
  66. data/lib/react_on_rails/locales/to_js.rb +37 -0
  67. data/lib/react_on_rails/locales/to_json.rb +27 -0
  68. data/lib/react_on_rails/prerender_error.rb +11 -15
  69. data/lib/react_on_rails/react_component/render_options.rb +4 -0
  70. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +41 -46
  71. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +7 -8
  72. data/lib/react_on_rails/utils.rb +14 -19
  73. data/lib/react_on_rails/version.rb +1 -1
  74. data/lib/react_on_rails/version_checker.rb +1 -0
  75. data/lib/react_on_rails/webpacker_utils.rb +13 -2
  76. data/lib/tasks/assets.rake +19 -44
  77. data/lib/tasks/locale.rake +4 -2
  78. data/package-scripts.yml +11 -8
  79. data/package.json +29 -28
  80. data/rakelib/dummy_apps.rake +1 -9
  81. data/rakelib/example_type.rb +3 -1
  82. data/rakelib/examples.rake +3 -0
  83. data/rakelib/lint.rake +2 -7
  84. data/rakelib/node_package.rake +2 -2
  85. data/rakelib/release.rake +0 -6
  86. data/rakelib/run_rspec.rake +5 -18
  87. data/react_on_rails.gemspec +3 -5
  88. data/tsconfig.json +14 -0
  89. data/webpackConfigLoader.js +3 -2
  90. data/yarn.lock +4170 -2197
  91. metadata +34 -57
  92. data/Gemfile.rails32 +0 -73
  93. data/docs/additional-reading/babel.md +0 -5
  94. data/docs/additional-reading/hot-reloading-rails-development-asset-pipeline.md +0 -47
  95. data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
  96. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
  97. data/lib/react_on_rails/assets_precompile.rb +0 -153
  98. 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: 11.2.1
4
+ version: 12.0.0.pre.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-06 00:00:00.000000000 Z
11
+ date: 2020-06-25 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: '1'
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: '1'
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.61.1
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.61.1
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,36 +353,43 @@ 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
362
+ - docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md
396
363
  - docs/basics/i18n.md
397
364
  - docs/basics/installation-into-an-existing-rails-app.md
398
365
  - docs/basics/migrating-from-react-rails.md
366
+ - docs/basics/minitest-configuration.md
399
367
  - docs/basics/react-server-rendering.md
400
368
  - docs/basics/recommended-project-structure.md
369
+ - docs/basics/render-functions-and-railscontext.md
401
370
  - docs/basics/rspec-configuration.md
402
371
  - docs/basics/upgrading-react-on-rails.md
403
372
  - docs/basics/webpack-configuration.md
404
373
  - docs/coding-style/style.md
374
+ - docs/contributor-info/errors-with-hooks.md
405
375
  - docs/contributor-info/generator-testing.md
406
376
  - docs/contributor-info/linters.md
377
+ - docs/contributor-info/pull-requests.md
407
378
  - docs/contributor-info/releasing.md
408
- - docs/misc-pending/code-splitting.md
409
- - docs/misc-pending/manual-installation-overview.md
410
- - docs/misc-pending/rails-assets.md
411
379
  - docs/misc/code_of_conduct.md
412
380
  - docs/misc/doctrine.md
413
- - docs/misc/rails3.md
381
+ - docs/outdated/code-splitting.md
382
+ - docs/outdated/heroku-deployment.md
383
+ - docs/outdated/how-react-on-rails-works.md
384
+ - docs/outdated/manual-installation-overview.md
385
+ - docs/outdated/rails-assets-relative-paths.md
386
+ - docs/outdated/rails-assets.md
387
+ - docs/outdated/rails3.md
414
388
  - docs/testimonials/hvmn.md
389
+ - docs/testimonials/resortpass.md
415
390
  - docs/testimonials/testimonials.md
416
391
  - docs/tutorial.md
392
+ - jest.config.js
417
393
  - lib/generators/USAGE
418
394
  - lib/generators/react_on_rails/base_generator.rb
419
395
  - lib/generators/react_on_rails/dev_tests_generator.rb
@@ -424,7 +400,7 @@ files:
424
400
  - lib/generators/react_on_rails/react_with_redux_generator.rb
425
401
  - lib/generators/react_on_rails/templates/.eslintrc
426
402
  - lib/generators/react_on_rails/templates/base/base/Procfile.dev
427
- - lib/generators/react_on_rails/templates/base/base/Procfile.dev-server
403
+ - lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr
428
404
  - lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rb
429
405
  - lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx
430
406
  - lib/generators/react_on_rails/templates/base/base/app/javascript/packs/registration.js.tt
@@ -445,7 +421,6 @@ files:
445
421
  - lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.jsx
446
422
  - lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js
447
423
  - lib/react_on_rails.rb
448
- - lib/react_on_rails/assets_precompile.rb
449
424
  - lib/react_on_rails/configuration.rb
450
425
  - lib/react_on_rails/controller.rb
451
426
  - lib/react_on_rails/engine.rb
@@ -454,7 +429,9 @@ files:
454
429
  - lib/react_on_rails/helper.rb
455
430
  - lib/react_on_rails/json_output.rb
456
431
  - lib/react_on_rails/json_parse_error.rb
457
- - lib/react_on_rails/locales_to_js.rb
432
+ - lib/react_on_rails/locales/base.rb
433
+ - lib/react_on_rails/locales/to_js.rb
434
+ - lib/react_on_rails/locales/to_json.rb
458
435
  - lib/react_on_rails/prerender_error.rb
459
436
  - lib/react_on_rails/react_component/render_options.rb
460
437
  - lib/react_on_rails/server_rendering_js_code.rb
@@ -489,6 +466,7 @@ files:
489
466
  - script/release
490
467
  - script/setup
491
468
  - script/test
469
+ - tsconfig.json
492
470
  - webpackConfigLoader.js
493
471
  - yarn.lock
494
472
  homepage: https://github.com/shakacode/react_on_rails
@@ -508,15 +486,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
508
486
  requirements:
509
487
  - - ">="
510
488
  - !ruby/object:Gem::Version
511
- version: 2.1.0
489
+ version: 2.5.0
512
490
  required_rubygems_version: !ruby/object:Gem::Requirement
513
491
  requirements:
514
- - - ">="
492
+ - - ">"
515
493
  - !ruby/object:Gem::Version
516
- version: '0'
494
+ version: 1.3.1
517
495
  requirements: []
518
- rubyforge_project:
519
- rubygems_version: 2.7.6
496
+ rubygems_version: 3.0.8
520
497
  signing_key:
521
498
  specification_version: 4
522
499
  summary: Rails with react server rendering with webpack.
@@ -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,12 +0,0 @@
1
- # You can run these commands in separate shells instead of using foreman
2
- web: rails s -p 3000
3
-
4
- # Next line runs the webpack-dev-server
5
- # You can edit config/webpacker.yml to set HMR to true to see hot reloading.
6
- # Note, hot and live reloading don't work with the default generator setup on top of
7
- # the rails/webpacker Webpack config with server rendering.
8
- # If you have server rendering enabled, modify the call to bin/webpack-dev-server line
9
- # so you add `--inline=false` and then CSS is not inlined.
10
- # Otherwise, you will have an error. If you want HMR and Server Rendering, see
11
- # the example in the https://github.com/shakacode/react-webpack-rails-tutorial
12
- client: sh -c 'rm -rf public/packs/* || true && bundle exec rake react_on_rails:locale && bin/webpack-dev-server'
@@ -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