react_on_rails 12.0.2 → 12.1.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 +12 -2
- data/.eslintrc +2 -1
- data/.github/workflows/lint-js-and-ruby.yml +53 -0
- data/.github/workflows/main.yml +178 -0
- data/.github/workflows/package-js-tests.yml +35 -0
- data/.github/workflows/rspec-package-specs.yml +45 -0
- data/.prettierrc +0 -3
- data/.rubocop.yml +46 -38
- data/CHANGELOG.md +35 -12
- data/CONTRIBUTING.md +4 -3
- data/Gemfile +1 -33
- data/Gemfile.development_dependencies +51 -0
- data/README.md +63 -55
- data/docs/{basics → additional-details}/generator-details.md +1 -6
- data/docs/{outdated → additional-details}/manual-installation-overview.md +6 -6
- data/docs/{basics → additional-details}/migrating-from-react-rails.md +0 -0
- data/docs/{additional-reading → additional-details}/recommended-project-structure.md +0 -0
- data/docs/{additional-reading → additional-details}/updating-dependencies.md +0 -0
- data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +10 -0
- data/docs/api/javascript-api.md +2 -2
- data/docs/api/redux-store-api.md +3 -3
- data/docs/api/view-helpers-api.md +7 -8
- data/docs/basics/client-vs-server-rendering.md +3 -3
- data/docs/basics/configuration.md +42 -25
- data/docs/basics/deployment.md +2 -2
- data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +16 -14
- data/docs/{outdated → basics}/how-react-on-rails-works.md +8 -9
- data/docs/basics/installation-into-an-existing-rails-app.md +13 -6
- data/docs/basics/react-server-rendering.md +3 -3
- data/docs/basics/rspec-configuration.md +10 -10
- data/docs/{tutorial.md → basics/tutorial.md} +23 -31
- data/docs/basics/upgrading-react-on-rails.md +32 -12
- data/docs/basics/webpack-configuration.md +4 -6
- data/docs/contributor-info/linters.md +5 -6
- data/docs/contributor-info/pull-requests.md +2 -4
- data/docs/contributor-info/releasing.md +1 -1
- data/docs/{additional-reading → deployment}/elastic-beanstalk.md +0 -0
- data/docs/{basics → deployment}/heroku-deployment.md +0 -0
- data/docs/home.md +382 -0
- data/docs/{additional-reading → javascript}/angular-js-integration-migration.md +0 -0
- data/docs/{additional-reading → javascript}/asset-pipeline.md +0 -0
- data/docs/{additional-reading → javascript}/capistrano-deployment.md +0 -0
- data/docs/{outdated → javascript}/code-splitting.md +5 -5
- data/docs/{additional-reading → javascript}/converting-from-custom-webpack-config-to-rails-webpacker-config.md +3 -3
- data/docs/{additional-reading → javascript}/credits.md +0 -0
- data/docs/{additional-reading → javascript}/foreman-issues.md +0 -0
- data/docs/{additional-reading → javascript}/images.md +5 -6
- data/docs/{additional-reading → javascript}/node-dependencies-and-npm.md +0 -0
- data/docs/{additional-reading → javascript}/react-and-redux.md +0 -0
- data/docs/{additional-reading → javascript}/react-helmet.md +0 -0
- data/docs/{additional-reading → javascript}/react-router.md +0 -0
- data/docs/{additional-reading → javascript}/server-rendering-tips.md +0 -0
- data/docs/{additional-reading → javascript}/troubleshooting-when-using-webpacker.md +0 -0
- data/docs/{additional-reading → javascript}/webpack-v1-notes.md +0 -0
- data/docs/{additional-reading → javascript}/webpack.md +0 -0
- data/docs/{articles.md → misc/articles.md} +1 -1
- data/docs/misc/doctrine.md +5 -5
- data/docs/{coding-style → misc}/style.md +0 -0
- data/docs/{additional-reading → misc}/tips.md +0 -0
- data/docs/outdated/deferred-rendering.md +39 -0
- data/docs/outdated/rails-assets-relative-paths.md +3 -3
- data/docs/outdated/rails-assets.md +8 -8
- data/docs/outdated/rails3.md +2 -2
- data/docs/rails-webpacker-react-integration-options.md +182 -0
- data/docs/{additional-reading → rails}/convert-rails-5-api-only-app.md +1 -1
- data/docs/{additional-reading → rails}/rails-engine-integration.md +0 -0
- data/docs/{additional-reading → rails}/rails_view_rendering_from_inline_javascript.md +0 -0
- data/docs/{additional-reading → rails}/turbolinks.md +0 -0
- data/docs/testimonials/testimonials.md +6 -6
- data/lib/generators/react_on_rails/base_generator.rb +8 -1
- data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +8 -2
- data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb +2 -2
- data/lib/react_on_rails/configuration.rb +2 -0
- data/lib/react_on_rails/git_utils.rb +3 -3
- data/lib/react_on_rails/helper.rb +15 -9
- data/lib/react_on_rails/locales/base.rb +3 -3
- data/lib/react_on_rails/locales/to_js.rb +0 -4
- data/lib/react_on_rails/locales/to_json.rb +0 -4
- data/lib/react_on_rails/prerender_error.rb +1 -1
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +6 -6
- data/lib/react_on_rails/test_helper.rb +2 -0
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +1 -1
- data/lib/react_on_rails/utils.rb +19 -3
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/webpacker_utils.rb +5 -1
- data/lib/tasks/assets.rake +20 -11
- data/package.json +24 -29
- data/rakelib/docker.rake +0 -5
- data/rakelib/lint.rake +3 -9
- data/rakelib/release.rake +27 -13
- data/rakelib/run_rspec.rake +10 -11
- data/rakelib/task_helpers.rb +16 -4
- data/react_on_rails.gemspec +3 -17
- data/yarn.lock +2272 -4960
- metadata +50 -225
- data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +0 -10
- data/docs/additional-reading/webpack-dev-server.md +0 -15
- data/ruby-lint.yml +0 -25
@@ -16,4 +16,4 @@ Rails will start creating the app and will skip the files you have already creat
|
|
16
16
|
3. If it is removeing some of your code then press "n" and add all additions manually
|
17
17
|
```
|
18
18
|
|
19
|
-
3. Run `bundle install` and follow [the instructions for installing into an existing Rails app](
|
19
|
+
3. Run `bundle install` and follow [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/basics/installation-into-an-existing-rails-app)
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# Testimonials
|
2
|
-
# [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](
|
2
|
+
# [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn)
|
3
3
|
|
4
4
|
> The price we paid for the consultation + the React on Rails pro license has already been made back a couple of times from hosting fees alone. The entire process was super hands off, and our core team was able to focus on shipping new feature during that sprint.
|
5
5
|
|
6
|
-
Full writeup [here](
|
6
|
+
Full writeup [here](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn).
|
7
7
|
|
8
8
|
---
|
9
9
|
|
10
|
-
# [Leora from ResortPass](
|
10
|
+
# [Leora from ResortPass](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass), December 10, 2018
|
11
11
|
|
12
|
-
Justin and his team were instrumental in assisting us in setting design foundations and standards for our transition to a react on rails application. Just three months of work with the team at Shaka code and we have a main page of our application server-side rendering at exponentially improved speeds.
|
12
|
+
Justin and his team were instrumental in assisting us in setting design foundations and standards for our transition to a react on rails application. Just three months of work with the team at Shaka code and we have a main page of our application server-side rendering at exponentially improved speeds.
|
13
13
|
|
14
|
-
Full writeup [here](
|
14
|
+
Full writeup [here](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass).
|
15
15
|
|
16
16
|
---
|
17
17
|
|
@@ -25,4 +25,4 @@ From Kyle Maune of Cooper Aerial, May 4, 2018
|
|
25
25
|
|
26
26
|
![image](https://user-images.githubusercontent.com/1118459/40891236-9b0b406e-671d-11e8-80ee-c026dbd1d5a2.png)
|
27
27
|
|
28
|
-
For more testimonials, see [Live Projects](PROJECTS.md) and [Kudos](KUDOS.md).
|
28
|
+
For more testimonials, see [Live Projects](https://github.com/shakacode/react_on_rails/tree/master/PROJECTS.md) and [Kudos](https://github.com/shakacode/react_on_rails/tree/master/KUDOS.md).
|
@@ -43,7 +43,14 @@ module ReactOnRails
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def add_yarn_dependencies
|
46
|
-
|
46
|
+
major_minor_patch_only = /\A\d+\.\d+\.\d+\z/.freeze
|
47
|
+
if ReactOnRails::VERSION.match?(major_minor_patch_only)
|
48
|
+
run "yarn add react-on-rails@#{ReactOnRails::VERSION} --exact"
|
49
|
+
else
|
50
|
+
# otherwise add latest
|
51
|
+
puts "Adding the lastest react-on-rails NPM module. Double check this is correct in package.json"
|
52
|
+
run "yarn add react-on-rails --exact"
|
53
|
+
end
|
47
54
|
end
|
48
55
|
|
49
56
|
def append_to_spec_rails_helper
|
@@ -13,9 +13,11 @@ require_relative "spec_helper"
|
|
13
13
|
require "rspec/rails"
|
14
14
|
require "capybara/rspec"
|
15
15
|
require "capybara/rails"
|
16
|
-
Capybara.javascript_driver = :selenium_chrome
|
17
16
|
Capybara.register_driver :selenium_chrome do |app|
|
18
|
-
|
17
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
18
|
+
options.add_argument("--headless")
|
19
|
+
options.add_argument("--disable-gpu")
|
20
|
+
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
19
21
|
end
|
20
22
|
|
21
23
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
@@ -38,6 +40,10 @@ end
|
|
38
40
|
# ActiveRecord::Migration.maintain_test_schema!
|
39
41
|
|
40
42
|
RSpec.configure do |config|
|
43
|
+
config.before(:each, type: :system, js: true) do
|
44
|
+
driven_by :selenium_chrome
|
45
|
+
end
|
46
|
+
|
41
47
|
# Ensure that if we are running js tests, we are using latest webpack assets
|
42
48
|
# This will use the defaults of :js and :server_rendering meta tags
|
43
49
|
ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb
RENAMED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
require_relative "../rails_helper"
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
describe "Hello World", js: true do
|
6
|
+
it "the hello world example works" do
|
7
7
|
visit "/hello_world"
|
8
8
|
expect(heading).to have_text("Hello World")
|
9
9
|
expect(message).to have_text("Stranger")
|
@@ -53,6 +53,7 @@ module ReactOnRails
|
|
53
53
|
:server_render_method, :random_dom_id,
|
54
54
|
:same_bundle_for_client_and_server
|
55
55
|
|
56
|
+
# rubocop:disable Metrics/AbcSize
|
56
57
|
def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender: nil,
|
57
58
|
replay_console: nil,
|
58
59
|
trace: nil, development_mode: nil,
|
@@ -98,6 +99,7 @@ module ReactOnRails
|
|
98
99
|
|
99
100
|
self.server_render_method = server_render_method
|
100
101
|
end
|
102
|
+
# rubocop:enable Metrics/AbcSize
|
101
103
|
|
102
104
|
# on ReactOnRails
|
103
105
|
def setup_config_values
|
@@ -10,10 +10,10 @@ module ReactOnRails
|
|
10
10
|
status = `git status --porcelain`
|
11
11
|
return false if $CHILD_STATUS.success? && status.empty?
|
12
12
|
|
13
|
-
error = if
|
14
|
-
"You do not have Git installed. Please install Git, and commit your changes before continuing"
|
15
|
-
else
|
13
|
+
error = if $CHILD_STATUS.success?
|
16
14
|
"You have uncommitted code. Please commit or stash your changes before continuing"
|
15
|
+
else
|
16
|
+
"You do not have Git installed. Please install Git, and commit your changes before continuing"
|
17
17
|
end
|
18
18
|
message_handler.add_error(error)
|
19
19
|
true
|
@@ -32,8 +32,8 @@ module ReactOnRails
|
|
32
32
|
# Exposing the react_component_name is necessary to both a plain ReactComponent as well as
|
33
33
|
# a generator:
|
34
34
|
# See README.md for how to "register" your react components.
|
35
|
-
# See spec/dummy/client/app/
|
36
|
-
# spec/dummy/client/app/
|
35
|
+
# See spec/dummy/client/app/packs/server-bundle.js and
|
36
|
+
# spec/dummy/client/app/packs/client-bundle.js for examples of this.
|
37
37
|
#
|
38
38
|
# options:
|
39
39
|
# props: Ruby Hash or JSON string which contains the properties to pass to the react object. Do
|
@@ -57,14 +57,15 @@ module ReactOnRails
|
|
57
57
|
server_rendered_html = internal_result[:result]["html"]
|
58
58
|
console_script = internal_result[:result]["consoleReplayScript"]
|
59
59
|
|
60
|
-
|
60
|
+
case server_rendered_html
|
61
|
+
when String
|
61
62
|
build_react_component_result_for_server_rendered_string(
|
62
63
|
server_rendered_html: server_rendered_html,
|
63
64
|
component_specification_tag: internal_result[:tag],
|
64
65
|
console_script: console_script,
|
65
66
|
render_options: internal_result[:render_options]
|
66
67
|
)
|
67
|
-
|
68
|
+
when Hash
|
68
69
|
msg = <<~MSG
|
69
70
|
Use react_component_hash (not react_component) to return a Hash to your ruby view code. See
|
70
71
|
https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/client/app/startup/ReactHelmetServerApp.jsx
|
@@ -169,7 +170,7 @@ module ReactOnRails
|
|
169
170
|
def redux_store_hydration_data
|
170
171
|
return if @registered_stores_defer_render.blank?
|
171
172
|
|
172
|
-
@registered_stores_defer_render.reduce(""
|
173
|
+
@registered_stores_defer_render.reduce(+"") do |accum, redux_store_data|
|
173
174
|
accum << render_redux_store_data(redux_store_data)
|
174
175
|
end.html_safe
|
175
176
|
end
|
@@ -243,7 +244,7 @@ module ReactOnRails
|
|
243
244
|
# second parameter passed to both component and store Render-Functions.
|
244
245
|
# This method can be called from views and from the controller, as `helpers.rails_context`
|
245
246
|
#
|
246
|
-
# rubocop:disable Metrics/AbcSize
|
247
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
247
248
|
def rails_context(server_side: true)
|
248
249
|
# ALERT: Keep in sync with node_package/src/types/index.ts for the properties of RailsContext
|
249
250
|
@rails_context ||= begin
|
@@ -254,8 +255,13 @@ module ReactOnRails
|
|
254
255
|
i18nLocale: I18n.locale,
|
255
256
|
i18nDefaultLocale: I18n.default_locale,
|
256
257
|
rorVersion: ReactOnRails::VERSION,
|
258
|
+
# TODO: v13 just use the version if existing
|
257
259
|
rorPro: ReactOnRails::Utils.react_on_rails_pro?
|
258
260
|
}
|
261
|
+
if ReactOnRails::Utils.react_on_rails_pro?
|
262
|
+
result[:rorProVersion] = ReactOnRails::Utils.react_on_rails_pro_version
|
263
|
+
end
|
264
|
+
|
259
265
|
if defined?(request) && request.present?
|
260
266
|
# Check for encoding of the request's original_url and try to force-encoding the
|
261
267
|
# URLs as UTF-8. This situation can occur in browsers that do not encode the
|
@@ -291,7 +297,7 @@ module ReactOnRails
|
|
291
297
|
|
292
298
|
@rails_context.merge(serverSide: server_side)
|
293
299
|
end
|
294
|
-
# rubocop:enable Metrics/AbcSize
|
300
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
295
301
|
|
296
302
|
private
|
297
303
|
|
@@ -486,13 +492,13 @@ module ReactOnRails
|
|
486
492
|
end
|
487
493
|
|
488
494
|
def initialize_redux_stores
|
489
|
-
result =
|
495
|
+
result = +<<-JS
|
490
496
|
ReactOnRails.clearHydratedStores();
|
491
497
|
JS
|
492
498
|
|
493
499
|
return result unless @registered_stores.present? || @registered_stores_defer_render.present?
|
494
500
|
|
495
|
-
declarations = "var reduxProps, store, storeGenerator;\n"
|
501
|
+
declarations = +"var reduxProps, store, storeGenerator;\n"
|
496
502
|
all_stores = (@registered_stores || []) + (@registered_stores_defer_render || [])
|
497
503
|
|
498
504
|
result << all_stores.each_with_object(declarations) do |redux_store_data, memo|
|
@@ -32,12 +32,12 @@ module ReactOnRails
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def exist_files
|
35
|
-
@exist_files ||= files.select
|
35
|
+
@exist_files ||= files.select { |file| File.exist?(file) }
|
36
36
|
end
|
37
37
|
|
38
38
|
def files_are_outdated
|
39
|
-
latest_yml = locale_files.map
|
40
|
-
earliest = exist_files.map
|
39
|
+
latest_yml = locale_files.map { |file| File.mtime(file) }.max
|
40
|
+
earliest = exist_files.map { |file| File.mtime(file) }.min
|
41
41
|
latest_yml > earliest
|
42
42
|
end
|
43
43
|
|
@@ -46,7 +46,7 @@ module ReactOnRails
|
|
46
46
|
private
|
47
47
|
|
48
48
|
def calc_message(component_name, console_messages, err, js_code, props)
|
49
|
-
message = "ERROR in SERVER PRERENDERING\n"
|
49
|
+
message = +"ERROR in SERVER PRERENDERING\n"
|
50
50
|
if err
|
51
51
|
message << <<~MSG
|
52
52
|
Encountered error: \"#{err}\"
|
@@ -47,6 +47,7 @@ module ReactOnRails
|
|
47
47
|
# Note, js_code does not have to be based on React.
|
48
48
|
# js_code MUST RETURN json stringify Object
|
49
49
|
# Calling code will probably call 'html_safe' on return value before rendering to the view.
|
50
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
50
51
|
def exec_server_render_js(js_code, render_options, js_evaluator = nil)
|
51
52
|
js_evaluator ||= self
|
52
53
|
if render_options.trace
|
@@ -67,16 +68,15 @@ module ReactOnRails
|
|
67
68
|
console_script = result["consoleReplayScript"]
|
68
69
|
console_script_lines = console_script.split("\n")
|
69
70
|
console_script_lines = console_script_lines[2..-2]
|
70
|
-
re = /console\.(log|error)\.apply\(console, \["\[SERVER\] (?<msg>.*)"\]\);/
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
Rails.logger.info { "[react_on_rails] #{match[:msg]}" } if match
|
75
|
-
end
|
71
|
+
re = /console\.(?:log|error)\.apply\(console, \["\[SERVER\] (?<msg>.*)"\]\);/
|
72
|
+
console_script_lines&.each do |line|
|
73
|
+
match = re.match(line)
|
74
|
+
Rails.logger.info { "[react_on_rails] #{match[:msg]}" } if match
|
76
75
|
end
|
77
76
|
end
|
78
77
|
result
|
79
78
|
end
|
79
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
80
80
|
|
81
81
|
def trace_js_code_used(msg, js_code, file_name = "tmp/server-generated.js", force: false)
|
82
82
|
return unless ReactOnRails.configuration.trace || force
|
@@ -52,6 +52,7 @@ module ReactOnRails
|
|
52
52
|
# don't provide one.
|
53
53
|
# webpack_generated_files List of files to check for up-to-date-status, defaulting to
|
54
54
|
# webpack_generated_files in your configuration
|
55
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
55
56
|
def self.ensure_assets_compiled(webpack_assets_status_checker: nil,
|
56
57
|
webpack_assets_compiler: nil,
|
57
58
|
source_path: nil,
|
@@ -96,4 +97,5 @@ module ReactOnRails
|
|
96
97
|
).call
|
97
98
|
end
|
98
99
|
end
|
100
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
99
101
|
end
|
@@ -8,7 +8,7 @@ module ReactOnRails
|
|
8
8
|
def compile_assets
|
9
9
|
if ReactOnRails.configuration.build_test_command.blank?
|
10
10
|
msg = <<~MSG
|
11
|
-
You are using the React on Rails test helper.
|
11
|
+
You are using the React on Rails test helper.
|
12
12
|
Either you used:
|
13
13
|
ReactOnRails::TestHelper.configure_rspec_to_compile_assets or
|
14
14
|
ReactOnRails::TestHelper.ensure_assets_compiled
|
data/lib/react_on_rails/utils.rb
CHANGED
@@ -34,7 +34,7 @@ module ReactOnRails
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.object_to_boolean(value)
|
37
|
-
[true, "true", "yes", 1, "1", "t"].include?(value.
|
37
|
+
[true, "true", "yes", 1, "1", "t"].include?(value.instance_of?(String) ? value.downcase : value)
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.server_rendering_is_enabled?
|
@@ -118,9 +118,11 @@ module ReactOnRails
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
+
# rubocop:disable Naming/VariableNumber
|
121
122
|
def self.rails_version_less_than_4_1_1
|
122
123
|
rails_version_less_than("4.1.1")
|
123
124
|
end
|
125
|
+
# rubocop:enable Naming/VariableNumber
|
124
126
|
|
125
127
|
module Required
|
126
128
|
def required(arg_name)
|
@@ -156,15 +158,29 @@ module ReactOnRails
|
|
156
158
|
end
|
157
159
|
|
158
160
|
def self.gem_available?(name)
|
159
|
-
Gem
|
161
|
+
Gem.loaded_specs[name].present?
|
160
162
|
rescue Gem::LoadError
|
161
163
|
false
|
162
164
|
rescue StandardError
|
163
165
|
Gem.available?(name).present?
|
164
166
|
end
|
165
167
|
|
168
|
+
# Todo -- remove this for v13, as we don't need both boolean and number
|
166
169
|
def self.react_on_rails_pro?
|
167
|
-
@react_on_rails_pro
|
170
|
+
return @react_on_rails_pro if defined?(@react_on_rails_pro)
|
171
|
+
|
172
|
+
@react_on_rails_pro = gem_available?("react_on_rails_pro")
|
173
|
+
end
|
174
|
+
|
175
|
+
# Return an empty string if React on Rails Pro is not installed
|
176
|
+
def self.react_on_rails_pro_version
|
177
|
+
return @react_on_rails_pro_version if defined?(@react_on_rails_pro_version)
|
178
|
+
|
179
|
+
@react_on_rails_pro_version = if react_on_rails_pro?
|
180
|
+
Gem.loaded_specs["react_on_rails_pro"].version.to_s
|
181
|
+
else
|
182
|
+
""
|
183
|
+
end
|
168
184
|
end
|
169
185
|
|
170
186
|
def self.smart_trim(str, max_length = 1000)
|
@@ -2,8 +2,12 @@
|
|
2
2
|
|
3
3
|
module ReactOnRails
|
4
4
|
module WebpackerUtils
|
5
|
+
# TODO: V13 code should be cleaned up so that the webpacker gem is required.
|
6
|
+
# This check should only be done at startup.
|
5
7
|
def self.using_webpacker?
|
6
|
-
|
8
|
+
return @using_webpacker if defined?(@using_webpacker)
|
9
|
+
|
10
|
+
@using_webpacker = ReactOnRails::Utils.gem_available?("webpacker")
|
7
11
|
end
|
8
12
|
|
9
13
|
def self.webpacker_webpack_production_config_exists?
|
data/lib/tasks/assets.rake
CHANGED
@@ -6,7 +6,6 @@
|
|
6
6
|
require "active_support"
|
7
7
|
|
8
8
|
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
|
9
|
-
ENV["NODE_ENV"] ||= "development"
|
10
9
|
|
11
10
|
unless ReactOnRails::WebpackerUtils.webpacker_webpack_production_config_exists?
|
12
11
|
# Ensure that rails/webpacker does not call bin/webpack if we're providing
|
@@ -20,8 +19,8 @@ unless ReactOnRails::WebpackerUtils.webpacker_webpack_production_config_exists?
|
|
20
19
|
# VERSIONS is per the rails/webpacker clean method definition.
|
21
20
|
# We set it very big so that it is not used, and then clean just
|
22
21
|
# removes files older than 1 hour.
|
23
|
-
|
24
|
-
Rake::Task["webpacker:clean"].invoke(
|
22
|
+
versions = 100_000
|
23
|
+
Rake::Task["webpacker:clean"].invoke(versions)
|
25
24
|
}
|
26
25
|
|
27
26
|
if Rake::Task.task_defined?("assets:precompile")
|
@@ -40,17 +39,27 @@ end
|
|
40
39
|
namespace :react_on_rails do
|
41
40
|
namespace :assets do
|
42
41
|
desc <<-DESC.strip_heredoc
|
43
|
-
Compile assets with webpack
|
44
|
-
Uses command defined with ReactOnRails.configuration.build_production_command
|
45
|
-
sh "#{ReactOnRails::Utils.prepend_cd_node_modules_directory('<ReactOnRails.configuration.build_production_command>')}"
|
46
|
-
Note: This command is not automatically added to assets:precompile if the rails/webpacker
|
42
|
+
Compile assets with webpack
|
43
|
+
Uses command defined with ReactOnRails.configuration.build_production_command
|
44
|
+
sh "#{ReactOnRails::Utils.prepend_cd_node_modules_directory('<ReactOnRails.configuration.build_production_command>')}"
|
45
|
+
Note: This command is not automatically added to assets:precompile if the rails/webpacker
|
47
46
|
configuration file config/webpack/production.js exists.
|
48
47
|
DESC
|
49
48
|
task webpack: :locale do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
build_production_command = ReactOnRails.configuration.build_production_command
|
50
|
+
if build_production_command.present?
|
51
|
+
if build_production_command.is_a?(String)
|
52
|
+
sh ReactOnRails::Utils.prepend_cd_node_modules_directory(
|
53
|
+
build_production_command
|
54
|
+
).to_s
|
55
|
+
elsif build_production_command.methods.include?(:call)
|
56
|
+
build_production_command.call
|
57
|
+
else
|
58
|
+
msg = "ReactonRails.configuration.build_production_command is improperly configured. "\
|
59
|
+
"Value = #{build_production_command} with class #{build_production_command.class}"
|
60
|
+
puts Rainbow(msg).red
|
61
|
+
exit!(1)
|
62
|
+
end
|
54
63
|
else
|
55
64
|
msg = <<~MSG
|
56
65
|
React on Rails is aborting webpack compilation from task react_on_rails:assets:webpack
|