react_on_rails 12.5.0 → 13.0.0.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 +3 -1
- data/.github/ISSUE_TEMPLATE/bug_report.md +23 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/workflows/main.yml +3 -3
- data/.gitignore +0 -3
- data/.prettierignore +2 -0
- data/CHANGELOG.md +22 -3
- data/Gemfile.development_dependencies +6 -6
- data/README.md +10 -15
- data/docs/deployment/heroku-deployment.md +1 -1
- data/docs/guides/configuration.md +23 -8
- data/docs/guides/hmr-and-hot-reloading-with-the-webpack-dev-server.md +4 -4
- data/docs/guides/how-react-on-rails-works.md +1 -1
- data/docs/guides/rspec-configuration.md +1 -1
- data/docs/guides/tutorial.md +15 -19
- data/docs/guides/upgrading-react-on-rails.md +15 -0
- data/docs/guides/webpack-configuration.md +1 -1
- data/docs/javascript/converting-from-custom-webpack-config-to-rails-webpacker-config.md +2 -2
- data/lib/generators/react_on_rails/base_generator.rb +9 -8
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +2 -2
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +2 -2
- data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +25 -8
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +2 -2
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpack.config.js.tt +15 -0
- data/lib/generators/react_on_rails/templates/base/base/config/webpacker.yml +2 -2
- data/lib/react_on_rails/configuration.rb +40 -41
- data/lib/react_on_rails/helper.rb +3 -3
- data/lib/react_on_rails/locales/base.rb +1 -3
- data/lib/react_on_rails/react_component/render_options.rb +14 -0
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +8 -6
- data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +3 -3
- data/lib/react_on_rails/test_helper.rb +2 -2
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/webpacker_utils.rb +2 -7
- data/lib/tasks/assets.rake +1 -42
- data/lib/tasks/locale.rake +1 -2
- data/package.json +1 -1
- data/rakelib/example_type.rb +5 -2
- data/rakelib/examples.rake +3 -10
- data/rakelib/release.rake +6 -0
- data/rakelib/task_helpers.rb +0 -7
- data/react_on_rails.gemspec +1 -2
- data/yarn.lock +117 -71
- metadata +10 -21
@@ -1,15 +1,32 @@
|
|
1
1
|
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/babel.config.js") %>
|
2
2
|
|
3
|
-
const defaultConfigFunc = require('@rails/webpacker/package/babel/preset.js');
|
4
|
-
|
5
3
|
module.exports = function (api) {
|
6
|
-
const
|
4
|
+
const defaultConfigFunc = require('shakapacker/package/babel/preset.js')
|
5
|
+
const resultConfig = defaultConfigFunc(api)
|
6
|
+
const isProductionEnv = api.env('production')
|
7
7
|
|
8
8
|
const changesOnDefault = {
|
9
|
-
|
10
|
-
|
9
|
+
presets: [
|
10
|
+
[
|
11
|
+
'@babel/preset-react',
|
12
|
+
{
|
13
|
+
development: !isProductionEnv,
|
14
|
+
useBuiltIns: true
|
15
|
+
}
|
16
|
+
]
|
17
|
+
].filter(Boolean),
|
18
|
+
plugins: [
|
19
|
+
process.env.WEBPACK_SERVE && 'react-refresh/babel',
|
20
|
+
isProductionEnv && ['babel-plugin-transform-react-remove-prop-types',
|
21
|
+
{
|
22
|
+
removeImport: true
|
23
|
+
}
|
24
|
+
]
|
25
|
+
].filter(Boolean),
|
26
|
+
}
|
11
27
|
|
12
|
-
resultConfig.
|
28
|
+
resultConfig.presets = [...resultConfig.presets, ...changesOnDefault.presets]
|
29
|
+
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins ]
|
13
30
|
|
14
|
-
return resultConfig
|
15
|
-
}
|
31
|
+
return resultConfig
|
32
|
+
}
|
data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
ReactOnRails.configure do |config|
|
7
7
|
# This configures the script to run to build the production assets by webpack. Set this to nil
|
8
8
|
# if you don't want react_on_rails building this file for you.
|
9
|
-
# If nil, then the standard
|
9
|
+
# If nil, then the standard shakacode/shakapacker assets:precompile will run
|
10
10
|
# config.build_production_command = nil
|
11
11
|
|
12
12
|
################################################################################
|
@@ -25,7 +25,7 @@ ReactOnRails.configure do |config|
|
|
25
25
|
#
|
26
26
|
# Alternately, you can remove the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`
|
27
27
|
# and set the config/webpacker.yml option for test to true.
|
28
|
-
config.build_test_command = "RAILS_ENV=test bin/
|
28
|
+
config.build_test_command = "RAILS_ENV=test bin/webpacker"
|
29
29
|
|
30
30
|
################################################################################
|
31
31
|
################################################################################
|
data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/commonWebpackConfig.js") %>
|
2
2
|
|
3
3
|
// Common configuration applying to client and server configuration
|
4
|
-
const { webpackConfig: baseClientWebpackConfig, merge } = require('
|
4
|
+
const { webpackConfig: baseClientWebpackConfig, merge } = require('shakapacker');
|
5
5
|
|
6
6
|
const commonOptions = {
|
7
7
|
resolve: {
|
data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/serverWebpackConfig.js") %>
|
2
2
|
|
3
|
-
const { merge, config } = require('
|
3
|
+
const { merge, config } = require('shakapacker');
|
4
4
|
const commonWebpackConfig = require('./commonWebpackConfig');
|
5
5
|
|
6
6
|
const webpack = require('webpack');
|
@@ -0,0 +1,15 @@
|
|
1
|
+
const { env, webpackConfig } = require('shakapacker')
|
2
|
+
const { existsSync } = require('fs')
|
3
|
+
const { resolve } = require('path')
|
4
|
+
|
5
|
+
const envSpecificConfig = () => {
|
6
|
+
const path = resolve(__dirname, `${env.nodeEnv}.js`)
|
7
|
+
if (existsSync(path)) {
|
8
|
+
console.log(`Loading ENV specific webpack configuration file ${path}`)
|
9
|
+
return require(path)
|
10
|
+
} else {
|
11
|
+
return webpackConfig
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
module.exports = envSpecificConfig()
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Note: You must restart bin/
|
1
|
+
# Note: You must restart bin/webpacker-dev-server for changes to take effect
|
2
2
|
|
3
3
|
default: &default
|
4
4
|
source_path: app/javascript
|
@@ -17,7 +17,7 @@ default: &default
|
|
17
17
|
|
18
18
|
development:
|
19
19
|
<<: *default
|
20
|
-
# This is false since we're running `bin/
|
20
|
+
# This is false since we're running `bin/webpacker -w` in Procfile.dev-setic
|
21
21
|
compile: false
|
22
22
|
|
23
23
|
# Reference: https://webpack.js.org/configuration/dev-server/
|
@@ -32,6 +32,7 @@ module ReactOnRails
|
|
32
32
|
# skip_display_none is deprecated
|
33
33
|
webpack_generated_files: %w[manifest.json],
|
34
34
|
rendering_extension: nil,
|
35
|
+
rendering_props_extension: nil,
|
35
36
|
server_render_method: nil,
|
36
37
|
build_test_command: "",
|
37
38
|
build_production_command: "",
|
@@ -51,7 +52,7 @@ module ReactOnRails
|
|
51
52
|
:build_production_command,
|
52
53
|
:i18n_dir, :i18n_yml_dir, :i18n_output_format,
|
53
54
|
:server_render_method, :random_dom_id,
|
54
|
-
:same_bundle_for_client_and_server
|
55
|
+
:same_bundle_for_client_and_server, :rendering_props_extension
|
55
56
|
|
56
57
|
# rubocop:disable Metrics/AbcSize
|
57
58
|
def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender: nil,
|
@@ -65,7 +66,7 @@ module ReactOnRails
|
|
65
66
|
build_production_command: nil,
|
66
67
|
same_bundle_for_client_and_server: nil,
|
67
68
|
i18n_dir: nil, i18n_yml_dir: nil, i18n_output_format: nil,
|
68
|
-
random_dom_id: nil, server_render_method: nil)
|
69
|
+
random_dom_id: nil, server_render_method: nil, rendering_props_extension: nil)
|
69
70
|
self.node_modules_location = node_modules_location.present? ? node_modules_location : Rails.root
|
70
71
|
self.generated_assets_dirs = generated_assets_dirs
|
71
72
|
self.generated_assets_dir = generated_assets_dir
|
@@ -87,6 +88,7 @@ module ReactOnRails
|
|
87
88
|
self.trace = trace.nil? ? Rails.env.development? : trace
|
88
89
|
self.raise_on_prerender_error = raise_on_prerender_error
|
89
90
|
self.skip_display_none = skip_display_none
|
91
|
+
self.rendering_props_extension = rendering_props_extension
|
90
92
|
|
91
93
|
# Server rendering:
|
92
94
|
self.server_bundle_js_file = server_bundle_js_file
|
@@ -111,44 +113,41 @@ module ReactOnRails
|
|
111
113
|
check_i18n_yml_directory_exists
|
112
114
|
check_server_render_method_is_only_execjs
|
113
115
|
error_if_using_webpacker_and_generated_assets_dir_not_match_public_output_path
|
114
|
-
check_deprecated_settings
|
116
|
+
# check_deprecated_settings
|
117
|
+
adjust_precompile_task
|
115
118
|
end
|
116
119
|
|
117
120
|
private
|
118
121
|
|
119
|
-
def
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
Rails
|
122
|
+
def adjust_precompile_task
|
123
|
+
skip_react_on_rails_precompile = %w[no false n f].include?(ENV["REACT_ON_RAILS_PRECOMPILE"])
|
124
|
+
|
125
|
+
return if skip_react_on_rails_precompile || build_production_command.blank?
|
126
|
+
|
127
|
+
# Ensure that shakacode/shakapacker does not call bin/webpacker if we're providing
|
128
|
+
# the build command.
|
129
|
+
ENV["WEBPACKER_PRECOMPILE"] = "false"
|
130
|
+
|
131
|
+
precompile_tasks = lambda {
|
132
|
+
Rake::Task["react_on_rails:assets:webpack"].invoke
|
133
|
+
puts "Invoking task webpacker:clean from React on Rails"
|
134
|
+
|
135
|
+
# VERSIONS is per the shakacode/shakapacker clean method definition.
|
136
|
+
# We set it very big so that it is not used, and then clean just
|
137
|
+
# removes files older than 1 hour.
|
138
|
+
versions = 100_000
|
139
|
+
Rake::Task["webpacker:clean"].invoke(versions)
|
140
|
+
}
|
141
|
+
|
142
|
+
if Rake::Task.task_defined?("assets:precompile")
|
143
|
+
Rake::Task["assets:precompile"].enhance do
|
144
|
+
precompile_tasks.call
|
145
|
+
end
|
146
|
+
else
|
147
|
+
Rake::Task.define_task("assets:precompile") do
|
148
|
+
precompile_tasks.call
|
149
|
+
end
|
131
150
|
end
|
132
|
-
#
|
133
|
-
# msg = <<~MSG
|
134
|
-
# ReactOnRails configuration for `build_production_command` is removed.
|
135
|
-
# Move this command into `bin/webpack` converting the script to a shell script.
|
136
|
-
# MSG
|
137
|
-
# raise ReactOnRails::Error, msg
|
138
|
-
# Commenting out until v13 when
|
139
|
-
# https://github.com/rails/webpacker/issues/2640 gets resolved
|
140
|
-
# if node_modules_location.present?
|
141
|
-
# Rails.logger.warn("ReactOnRails configuration for `node_modules_location` is deprecated. "\
|
142
|
-
# "Instead, prepend a `cd client` (or whichever location) before your test command.")
|
143
|
-
# end
|
144
|
-
#
|
145
|
-
# return unless build_production_command.present?
|
146
|
-
#
|
147
|
-
# msg = <<~MSG
|
148
|
-
# ReactOnRails configuration for `build_production_command` is removed.
|
149
|
-
# Move this command into `bin/webpack` converting the script to a shell script.
|
150
|
-
# MSG
|
151
|
-
# raise ReactOnRails::Error, msg
|
152
151
|
end
|
153
152
|
|
154
153
|
def error_if_using_webpacker_and_generated_assets_dir_not_match_public_output_path
|
@@ -160,7 +159,7 @@ module ReactOnRails
|
|
160
159
|
|
161
160
|
if File.expand_path(generated_assets_dir) == webpacker_public_output_path.to_s
|
162
161
|
Rails.logger.warn("You specified generated_assets_dir in `config/initializers/react_on_rails.rb` "\
|
163
|
-
|
162
|
+
"with Webpacker. Remove this line from your configuration file.")
|
164
163
|
else
|
165
164
|
msg = <<~MSG
|
166
165
|
Error configuring /config/initializers/react_on_rails.rb: You are using webpacker
|
@@ -222,19 +221,19 @@ module ReactOnRails
|
|
222
221
|
if ReactOnRails::WebpackerUtils.using_webpacker?
|
223
222
|
webpacker_public_output_path = ReactOnRails::WebpackerUtils.webpacker_public_output_path
|
224
223
|
Rails.logger.warn "Error configuring config/initializers/react_on_rails. Define neither the "\
|
225
|
-
|
226
|
-
|
224
|
+
"generated_assets_dirs no the generated_assets_dir when using Webpacker. This is defined by "\
|
225
|
+
"public_output_path specified in webpacker.yml = #{webpacker_public_output_path}."
|
227
226
|
return
|
228
227
|
end
|
229
228
|
|
230
229
|
Rails.logger.warn "[DEPRECATION] ReactOnRails: Use config.generated_assets_dir rather than "\
|
231
|
-
|
230
|
+
"generated_assets_dirs"
|
232
231
|
if generated_assets_dir.blank?
|
233
232
|
self.generated_assets_dir = generated_assets_dirs
|
234
233
|
else
|
235
234
|
Rails.logger.warn "[DEPRECATION] ReactOnRails. You have both generated_assets_dirs and "\
|
236
|
-
|
237
|
-
|
235
|
+
"generated_assets_dir defined. Define ONLY generated_assets_dir if NOT using Webpacker"\
|
236
|
+
" and define neither if using Webpacker"
|
238
237
|
end
|
239
238
|
end
|
240
239
|
|
@@ -154,7 +154,7 @@ module ReactOnRails
|
|
154
154
|
@registered_stores_defer_render ||= []
|
155
155
|
@registered_stores_defer_render << redux_store_data
|
156
156
|
"YOU SHOULD NOT SEE THIS ON YOUR VIEW -- Uses as a code block, like <% redux_store %> "\
|
157
|
-
|
157
|
+
"and not <%= redux store %>"
|
158
158
|
else
|
159
159
|
@registered_stores ||= []
|
160
160
|
@registered_stores << redux_store_data
|
@@ -244,7 +244,7 @@ module ReactOnRails
|
|
244
244
|
|
245
245
|
unless hash_or_string.is_a?(String) || hash_or_string.is_a?(Hash)
|
246
246
|
raise ReactOnRails::Error, "#{__method__} only accepts String or Hash as argument "\
|
247
|
-
|
247
|
+
"(#{hash_or_string.class} given)."
|
248
248
|
end
|
249
249
|
|
250
250
|
json_value = hash_or_string.is_a?(String) ? hash_or_string : hash_or_string.to_json
|
@@ -413,7 +413,7 @@ module ReactOnRails
|
|
413
413
|
# Setup the page_loaded_js, which is the same regardless of prerendering or not!
|
414
414
|
# The reason is that React is smart about not doing extra work if the server rendering did its job.
|
415
415
|
component_specification_tag = content_tag(:script,
|
416
|
-
json_safe_and_pretty(render_options.
|
416
|
+
json_safe_and_pretty(render_options.client_props).html_safe,
|
417
417
|
type: "application/json",
|
418
418
|
class: "js-react-on-rails-component",
|
419
419
|
"data-component-name" => render_options.react_component_name,
|
@@ -27,6 +27,20 @@ module ReactOnRails
|
|
27
27
|
options.fetch(:props) { NO_PROPS }
|
28
28
|
end
|
29
29
|
|
30
|
+
def client_props
|
31
|
+
props_extension = ReactOnRails.configuration.rendering_props_extension
|
32
|
+
if props_extension.present?
|
33
|
+
if props_extension.respond_to?(:adjust_props_for_client_side_hydration)
|
34
|
+
return props_extension.adjust_props_for_client_side_hydration(react_component_name,
|
35
|
+
props.clone)
|
36
|
+
end
|
37
|
+
|
38
|
+
raise ReactOnRails::Error, "ReactOnRails: your rendering_props_extension module is missing the "\
|
39
|
+
"required adjust_props_for_client_side_hydration method & can not be used"
|
40
|
+
end
|
41
|
+
props
|
42
|
+
end
|
43
|
+
|
30
44
|
def random_dom_id
|
31
45
|
retrieve_configuration_value_for(:random_dom_id)
|
32
46
|
end
|
@@ -133,15 +133,15 @@ module ReactOnRails
|
|
133
133
|
if ReactOnRails.configuration.trace
|
134
134
|
Rails.logger.info do
|
135
135
|
"[react_on_rails] Created JavaScript context with file "\
|
136
|
-
|
136
|
+
"#{ReactOnRails::Utils.server_bundle_js_file_path}"
|
137
137
|
end
|
138
138
|
end
|
139
139
|
ExecJS.compile(base_js_code)
|
140
140
|
rescue StandardError => e
|
141
141
|
msg = "ERROR when compiling base_js_code! "\
|
142
|
-
|
143
|
-
|
144
|
-
|
142
|
+
"See file #{file_name} to "\
|
143
|
+
"correlate line numbers of error. Error is\n\n#{e.message}"\
|
144
|
+
"\n\n#{e.backtrace.join("\n")}"
|
145
145
|
Rails.logger.error(msg)
|
146
146
|
trace_js_code_used("Error when compiling JavaScript code for the context.", base_js_code,
|
147
147
|
file_name, force: true)
|
@@ -150,7 +150,9 @@ module ReactOnRails
|
|
150
150
|
end
|
151
151
|
|
152
152
|
def execjs_timer_polyfills
|
153
|
-
if ReactOnRails::Utils.react_on_rails_pro? &&
|
153
|
+
if ReactOnRails::Utils.react_on_rails_pro? &&
|
154
|
+
ReactOnRailsPro.configuration.respond_to?(:include_execjs_polyfills) &&
|
155
|
+
ReactOnRailsPro.configuration.include_execjs_polyfills == false
|
154
156
|
return ""
|
155
157
|
end
|
156
158
|
|
@@ -184,7 +186,7 @@ module ReactOnRails
|
|
184
186
|
def undefined_for_exec_js_logging(function_name)
|
185
187
|
if ReactOnRails.configuration.trace
|
186
188
|
"console.error('[React on Rails Rendering] #{function_name} is not defined for server rendering.');\n"\
|
187
|
-
|
189
|
+
" console.error(getStackTrace().join('\\n'));"
|
188
190
|
else
|
189
191
|
""
|
190
192
|
end
|
@@ -66,10 +66,10 @@ module ReactOnRails
|
|
66
66
|
file_list = make_file_list(make_globs(generated_assets_full_path)).to_ary
|
67
67
|
puts "V" * 80
|
68
68
|
puts "Please define config.webpack_generated_files (array) so the test helper knows "\
|
69
|
-
|
70
|
-
|
69
|
+
"which files are required. If you are using webpacker, you typically need to only "\
|
70
|
+
"include 'manifest.json'."
|
71
71
|
puts "Detected the possible following files to check for webpack compilation in "\
|
72
|
-
|
72
|
+
"#{generated_assets_full_path}"
|
73
73
|
puts file_list.join("\n")
|
74
74
|
puts "^" * 80
|
75
75
|
file_list
|
@@ -72,8 +72,8 @@ module ReactOnRails
|
|
72
72
|
unless @printed_once
|
73
73
|
puts
|
74
74
|
puts "====> React On Rails: Checking files in "\
|
75
|
-
|
76
|
-
|
75
|
+
"#{webpack_assets_status_checker.generated_assets_full_path} for "\
|
76
|
+
"outdated/missing bundles based on source_path #{source_path}"
|
77
77
|
puts
|
78
78
|
@printed_once = true
|
79
79
|
|
@@ -7,13 +7,8 @@ module ReactOnRails
|
|
7
7
|
def self.using_webpacker?
|
8
8
|
return @using_webpacker if defined?(@using_webpacker)
|
9
9
|
|
10
|
-
@using_webpacker = ReactOnRails::Utils.gem_available?("webpacker")
|
11
|
-
|
12
|
-
|
13
|
-
def self.webpacker_webpack_production_config_exists?
|
14
|
-
webpacker_webpack_config_abs_path = File.join(Rails.root,
|
15
|
-
"config/webpack/production.js")
|
16
|
-
File.exist?(webpacker_webpack_config_abs_path)
|
10
|
+
@using_webpacker = ReactOnRails::Utils.gem_available?("webpacker") ||
|
11
|
+
ReactOnRails::Utils.gem_available?("shakapacker")
|
17
12
|
end
|
18
13
|
|
19
14
|
def self.dev_server_running?
|
data/lib/tasks/assets.rake
CHANGED
@@ -1,46 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Important: The default assets:precompile is modified ONLY if the rails/webpacker webpack config
|
4
|
-
# does not exist!
|
5
|
-
|
6
|
-
require "active_support"
|
7
|
-
|
8
|
-
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
|
9
|
-
|
10
|
-
skip_react_on_rails_precompile = %w[no false n f].include?(ENV["REACT_ON_RAILS_PRECOMPILE"])
|
11
|
-
|
12
|
-
if !skip_react_on_rails_precompile && ReactOnRails.configuration.build_production_command.present?
|
13
|
-
# Ensure that rails/webpacker does not call bin/webpack if we're providing
|
14
|
-
# the build command.
|
15
|
-
ENV["WEBPACKER_PRECOMPILE"] = "false"
|
16
|
-
|
17
|
-
precompile_tasks = lambda {
|
18
|
-
Rake::Task["react_on_rails:assets:webpack"].invoke
|
19
|
-
puts "Invoking task webpacker:clean from React on Rails"
|
20
|
-
|
21
|
-
# VERSIONS is per the rails/webpacker clean method definition.
|
22
|
-
# We set it very big so that it is not used, and then clean just
|
23
|
-
# removes files older than 1 hour.
|
24
|
-
versions = 100_000
|
25
|
-
Rake::Task["webpacker:clean"].invoke(versions)
|
26
|
-
}
|
27
|
-
|
28
|
-
if Rake::Task.task_defined?("assets:precompile")
|
29
|
-
Rake::Task["assets:precompile"].enhance do
|
30
|
-
precompile_tasks.call
|
31
|
-
end
|
32
|
-
else
|
33
|
-
Rake::Task.define_task("assets:precompile") do
|
34
|
-
precompile_tasks.call
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Sprockets independent tasks
|
40
3
|
# rubocop:disable Metrics/BlockLength
|
41
4
|
namespace :react_on_rails do
|
42
5
|
namespace :assets do
|
43
|
-
desc <<~DESC
|
6
|
+
desc <<~DESC
|
44
7
|
If config.build_production_command is defined, this command is automatically
|
45
8
|
added to task assets:precompile and the regular webpacker compile will not run.
|
46
9
|
The defined command is either a script or a module with a method `call`.
|
@@ -65,10 +28,6 @@ namespace :react_on_rails do
|
|
65
28
|
msg = <<~MSG
|
66
29
|
React on Rails is aborting webpack compilation from task react_on_rails:assets:webpack
|
67
30
|
because you do not have the `config.build_production_command` defined.
|
68
|
-
|
69
|
-
Note, this task may have run as part of `assets:precompile`. If file
|
70
|
-
config/webpack/production.js does not exist, React on Rails will modify
|
71
|
-
the default `asset:precompile` to run task `react_on_rails:assets:webpack`.
|
72
31
|
MSG
|
73
32
|
puts Rainbow(msg).red
|
74
33
|
exit!(1)
|
data/lib/tasks/locale.rake
CHANGED
@@ -3,10 +3,9 @@
|
|
3
3
|
require "react_on_rails/locales/base"
|
4
4
|
require "react_on_rails/locales/to_js"
|
5
5
|
require "react_on_rails/locales/to_json"
|
6
|
-
require "active_support"
|
7
6
|
|
8
7
|
namespace :react_on_rails do
|
9
|
-
desc
|
8
|
+
desc <<~DESC
|
10
9
|
Generate i18n javascript files
|
11
10
|
This task generates javascript locale files: `translations.js` & `default.js` and places them in
|
12
11
|
the "ReactOnRails.configuration.i18n_dir".
|
data/package.json
CHANGED
data/rakelib/example_type.rb
CHANGED
@@ -45,7 +45,10 @@ module ReactOnRails
|
|
45
45
|
# Gems we need to add to the Gemfile before bundle installing
|
46
46
|
def required_gems
|
47
47
|
relative_gem_root = Pathname(gem_root).relative_path_from(Pathname(dir))
|
48
|
-
[
|
48
|
+
[
|
49
|
+
"gem 'react_on_rails', path: '#{relative_gem_root}'",
|
50
|
+
"gem 'shakapacker'"
|
51
|
+
]
|
49
52
|
end
|
50
53
|
|
51
54
|
# Options we pass when running `rails new` from the command-line.
|
@@ -78,7 +81,7 @@ module ReactOnRails
|
|
78
81
|
# Assumes we are inside a rails app's folder and necessary gems have been installed
|
79
82
|
def generator_shell_commands
|
80
83
|
shell_commands = []
|
81
|
-
shell_commands << "rails generate react_on_rails:install #{generator_options} --ignore-warnings"
|
84
|
+
shell_commands << "rails generate react_on_rails:install #{generator_options} --ignore-warnings --force"
|
82
85
|
shell_commands << "rails generate react_on_rails:dev_tests #{generator_options}"
|
83
86
|
end
|
84
87
|
|
data/rakelib/examples.rake
CHANGED
@@ -16,7 +16,7 @@ namespace :examples do # rubocop:disable Metrics/BlockLength
|
|
16
16
|
# Loads data from examples_config.yml and instantiates corresponding ExampleType objects
|
17
17
|
examples_config_file = File.expand_path("examples_config.yml", __dir__)
|
18
18
|
examples_config = symbolize_keys(YAML.safe_load(File.read(examples_config_file)))
|
19
|
-
examples_config[:example_type_data].each { |example_type_data| ExampleType.new(symbolize_keys(example_type_data)) }
|
19
|
+
examples_config[:example_type_data].each { |example_type_data| ExampleType.new(**symbolize_keys(example_type_data)) }
|
20
20
|
|
21
21
|
# Define tasks for each example type
|
22
22
|
ExampleType.all.each do |example_type|
|
@@ -30,19 +30,12 @@ namespace :examples do # rubocop:disable Metrics/BlockLength
|
|
30
30
|
desc "Generates #{example_type.name_pretty}"
|
31
31
|
task example_type.gen_task_name_short => example_type.clobber_task_name do
|
32
32
|
mkdir_p(example_type.dir)
|
33
|
-
|
34
|
-
example_type.rails_options += " --webpack"
|
35
|
-
elsif Rails::VERSION::MAJOR >= 7
|
36
|
-
example_type.rails_options += "--javascript=webpack"
|
37
|
-
end
|
33
|
+
example_type.rails_options += "--skip-javascript"
|
38
34
|
sh_in_dir(examples_dir, "rails new #{example_type.name} #{example_type.rails_options}")
|
39
35
|
sh_in_dir(example_type.dir, "touch .gitignore")
|
40
|
-
copy_generator_webpacker_yml_to(example_type.dir)
|
41
|
-
sh_in_dir(example_type.dir, "bundle add webpacker --version 6.0.0.rc.6")
|
42
|
-
sh_in_dir(example_type.dir, "rake webpacker:install")
|
43
|
-
sh_in_dir(example_type.dir, "bundle binstubs --path=#{example_type.dir}/bin webpacker")
|
44
36
|
append_to_gemfile(example_type.gemfile, example_type.required_gems)
|
45
37
|
bundle_install_in(example_type.dir)
|
38
|
+
sh_in_dir(example_type.dir, "rake webpacker:install")
|
46
39
|
sh_in_dir(example_type.dir, example_type.generator_shell_commands)
|
47
40
|
sh_in_dir(example_type.dir, "yarn")
|
48
41
|
end
|
data/rakelib/release.rake
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "bundler"
|
3
4
|
require_relative "task_helpers"
|
4
5
|
require_relative File.join(gem_root, "lib", "react_on_rails", "version_syntax_converter")
|
5
6
|
require_relative File.join(gem_root, "lib", "react_on_rails", "git_utils")
|
@@ -27,6 +28,8 @@ which are installed via `bundle install` and `yarn global add release-it`
|
|
27
28
|
automatically perform a patch version bump.
|
28
29
|
2nd argument: Perform a dry run by passing 'true' as a second argument.
|
29
30
|
|
31
|
+
Note, accept defaults for npmjs options. Script will pause to get 2FA tokens.
|
32
|
+
|
30
33
|
Example: `rake release[2.1.0,false]`")
|
31
34
|
task :release, %i[gem_version dry_run tools_install] do |_t, args|
|
32
35
|
include ReactOnRails::TaskHelpers
|
@@ -57,6 +60,7 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
|
|
57
60
|
# Update dummy app's Gemfile.lock
|
58
61
|
bundle_install_in(dummy_app_dir)
|
59
62
|
|
63
|
+
puts "Carefully add your OTP for NPM. If you get an error, 'git reset --hard' and start over."
|
60
64
|
# Will bump the yarn version, commit, tag the commit, push to repo, and release on yarn
|
61
65
|
release_it_command = +"release-it"
|
62
66
|
release_it_command << " #{npm_version}" unless npm_version.strip.empty?
|
@@ -65,6 +69,8 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
|
|
65
69
|
sh_in_dir(gem_root, release_it_command)
|
66
70
|
|
67
71
|
# Release the new gem version
|
72
|
+
|
73
|
+
puts "Carefully add your OTP for Rubygems. If you get an error, run 'gem release' again."
|
68
74
|
sh_in_dir(gem_root, "gem release") unless is_dry_run
|
69
75
|
|
70
76
|
msg = <<~MSG
|
data/rakelib/task_helpers.rb
CHANGED
@@ -12,13 +12,6 @@ module ReactOnRails
|
|
12
12
|
File.join(gem_root, "gen-examples", "examples")
|
13
13
|
end
|
14
14
|
|
15
|
-
# This method is used to prevent an error that when installing webpacker 6.0.0.rc.6
|
16
|
-
# without a previous config/webpacker.yml will throw and error
|
17
|
-
def copy_generator_webpacker_yml_to(destination)
|
18
|
-
webpacker_file = File.join(gem_root, "lib/generators/react_on_rails/templates/base/base/config/webpacker.yml")
|
19
|
-
sh %( cp #{webpacker_file} #{destination}/config/webpacker.yml )
|
20
|
-
end
|
21
|
-
|
22
15
|
def dummy_app_dir
|
23
16
|
File.join(gem_root, "spec/dummy")
|
24
17
|
end
|
data/react_on_rails.gemspec
CHANGED
@@ -28,9 +28,8 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_dependency "addressable"
|
29
29
|
s.add_dependency "connection_pool"
|
30
30
|
s.add_dependency "execjs", "~> 2.5"
|
31
|
-
s.add_dependency "rails", ">=
|
31
|
+
s.add_dependency "rails", ">= 5.2"
|
32
32
|
s.add_dependency "rainbow", "~> 3.0"
|
33
|
-
s.add_dependency "webpacker", ">= 4.0"
|
34
33
|
|
35
34
|
s.add_development_dependency "bundler", "~> 2"
|
36
35
|
s.add_development_dependency "gem-release"
|