react_on_rails 11.3.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.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 +65 -6
- data/CONTRIBUTING.md +60 -71
- data/Gemfile +3 -4
- data/{COMM-LICENSE → REACT-ON-RAILS-PRO-LICENSE} +6 -9
- data/README.md +129 -92
- 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 +83 -69
- data/docs/basics/deployment.md +2 -4
- data/docs/basics/heroku-deployment.md +24 -0
- data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +49 -0
- data/docs/basics/i18n.md +45 -23
- data/docs/basics/installation-into-an-existing-rails-app.md +4 -9
- data/docs/basics/react-server-rendering.md +1 -1
- data/docs/basics/recommended-project-structure.md +5 -22
- data/docs/basics/{generator-functions-and-railscontext.md → render-functions-and-railscontext.md} +59 -21
- data/docs/basics/rspec-configuration.md +27 -16
- data/docs/basics/upgrading-react-on-rails.md +58 -2
- data/docs/basics/webpack-configuration.md +18 -8
- 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/{basics → outdated}/how-react-on-rails-works.md +8 -4
- 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 +2 -12
- data/docs/tutorial.md +94 -68
- data/jest.config.js +4 -0
- data/lib/generators/react_on_rails/base_generator.rb +2 -2
- 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/Procfile.dev +3 -1
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +26 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +20 -40
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +4 -1
- 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/configuration.rb +58 -28
- 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 +150 -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/test_helper/webpack_assets_compiler.rb +17 -0
- 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 +19 -2
- data/lib/react_on_rails.rb +3 -1
- data/lib/tasks/assets.rake +33 -46
- data/lib/tasks/locale.rake +4 -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/release.rake +0 -6
- data/rakelib/run_rspec.rake +5 -18
- data/react_on_rails.gemspec +4 -5
- data/tsconfig.json +14 -0
- data/webpackConfigLoader.js +3 -2
- data/yarn.lock +4333 -2209
- metadata +44 -55
- data/Gemfile.rails32 +0 -73
- data/docs/additional-reading/babel.md +0 -5
- data/docs/additional-reading/heroku-deployment.md +0 -92
- 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/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
- data/lib/react_on_rails/assets_precompile.rb +0 -153
- data/lib/react_on_rails/locales_to_js.rb +0 -138
- /data/docs/{misc → outdated}/rails3.md +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "erb"
|
|
4
|
+
|
|
5
|
+
module ReactOnRails
|
|
6
|
+
module Locales
|
|
7
|
+
class ToJs < Base
|
|
8
|
+
def initialize
|
|
9
|
+
super
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def file_format
|
|
15
|
+
"js"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def template_translations
|
|
19
|
+
<<-JS.strip_heredoc
|
|
20
|
+
export const translations = #{@translations};
|
|
21
|
+
JS
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def template_default
|
|
25
|
+
<<-JS.strip_heredoc
|
|
26
|
+
import { defineMessages } from 'react-intl';
|
|
27
|
+
|
|
28
|
+
const defaultLocale = \'#{default_locale}\';
|
|
29
|
+
|
|
30
|
+
const defaultMessages = defineMessages(#{@defaults});
|
|
31
|
+
|
|
32
|
+
export { defaultMessages, defaultLocale };
|
|
33
|
+
JS
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "erb"
|
|
4
|
+
|
|
5
|
+
module ReactOnRails
|
|
6
|
+
module Locales
|
|
7
|
+
class ToJson < Base
|
|
8
|
+
def initialize
|
|
9
|
+
super
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def file_format
|
|
15
|
+
"json"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def template_translations
|
|
19
|
+
@translations
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def template_default
|
|
23
|
+
@defaults
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -48,33 +48,29 @@ module ReactOnRails
|
|
|
48
48
|
def calc_message(component_name, console_messages, err, js_code, props)
|
|
49
49
|
message = "ERROR in SERVER PRERENDERING\n".dup
|
|
50
50
|
if err
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
Encountered error: \"#{err}\"
|
|
51
|
+
message << <<~MSG
|
|
52
|
+
Encountered error: \"#{err}\"
|
|
54
53
|
MSG
|
|
55
|
-
|
|
54
|
+
|
|
56
55
|
backtrace = err.backtrace.join("\n")
|
|
57
56
|
else
|
|
58
57
|
backtrace = nil
|
|
59
58
|
end
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
when prerendering #{component_name} with props: #{Utils.smart_trim(props, MAX_ERROR_SNIPPET_TO_LOG)}
|
|
59
|
+
message << <<~MSG
|
|
60
|
+
when prerendering #{component_name} with props: #{Utils.smart_trim(props, MAX_ERROR_SNIPPET_TO_LOG)}
|
|
63
61
|
|
|
64
|
-
code:
|
|
62
|
+
code:
|
|
65
63
|
|
|
66
|
-
#{Utils.smart_trim(js_code, MAX_ERROR_SNIPPET_TO_LOG)}
|
|
64
|
+
#{Utils.smart_trim(js_code, MAX_ERROR_SNIPPET_TO_LOG)}
|
|
67
65
|
|
|
68
66
|
MSG
|
|
69
|
-
# rubocop:enable Layout/IndentHeredoc
|
|
70
67
|
|
|
71
68
|
if console_messages
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
#{console_messages}
|
|
69
|
+
message << <<~MSG
|
|
70
|
+
console messages:
|
|
71
|
+
#{console_messages}
|
|
76
72
|
MSG
|
|
77
|
-
|
|
73
|
+
|
|
78
74
|
end
|
|
79
75
|
[backtrace, message]
|
|
80
76
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "open-uri"
|
|
4
|
+
require "execjs"
|
|
4
5
|
|
|
5
6
|
module ReactOnRails
|
|
6
7
|
module ServerRenderingPool
|
|
@@ -121,14 +122,12 @@ module ReactOnRails
|
|
|
121
122
|
return if ReactOnRails.configuration.server_bundle_js_file.blank?
|
|
122
123
|
|
|
123
124
|
bundle_js_code = read_bundle_js_code
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
#{
|
|
128
|
-
#{execjs_timer_polyfills}
|
|
129
|
-
#{bundle_js_code};
|
|
125
|
+
base_js_code = <<~JS
|
|
126
|
+
#{console_polyfill}
|
|
127
|
+
#{execjs_timer_polyfills}
|
|
128
|
+
#{bundle_js_code};
|
|
130
129
|
JS
|
|
131
|
-
|
|
130
|
+
|
|
132
131
|
file_name = "tmp/base_js_code.js"
|
|
133
132
|
begin
|
|
134
133
|
if ReactOnRails.configuration.trace
|
|
@@ -151,33 +150,31 @@ module ReactOnRails
|
|
|
151
150
|
end
|
|
152
151
|
|
|
153
152
|
def execjs_timer_polyfills
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
153
|
+
<<~JS
|
|
154
|
+
function getStackTrace () {
|
|
155
|
+
var stack;
|
|
156
|
+
try {
|
|
157
|
+
throw new Error('');
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
stack = error.stack || '';
|
|
161
|
+
}
|
|
162
|
+
stack = stack.split('\\n').map(function (line) { return line.trim(); });
|
|
163
|
+
return stack.splice(stack[0] == 'Error' ? 2 : 1);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function setInterval() {
|
|
167
|
+
#{undefined_for_exec_js_logging('setInterval')}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function setTimeout() {
|
|
171
|
+
#{undefined_for_exec_js_logging('setTimeout')}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function clearTimeout() {
|
|
175
|
+
#{undefined_for_exec_js_logging('clearTimeout')}
|
|
176
|
+
}
|
|
179
177
|
JS
|
|
180
|
-
# rubocop:enable Layout/IndentHeredoc
|
|
181
178
|
end
|
|
182
179
|
|
|
183
180
|
def undefined_for_exec_js_logging(function_name)
|
|
@@ -191,20 +188,18 @@ function clearTimeout() {
|
|
|
191
188
|
|
|
192
189
|
# Reimplement console methods for replaying on the client
|
|
193
190
|
def console_polyfill
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
[
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
});
|
|
191
|
+
<<~JS
|
|
192
|
+
var console = { history: [] };
|
|
193
|
+
['error', 'log', 'info', 'warn'].forEach(function (level) {
|
|
194
|
+
console[level] = function () {
|
|
195
|
+
var argArray = Array.prototype.slice.call(arguments);
|
|
196
|
+
if (argArray.length > 0) {
|
|
197
|
+
argArray[0] = '[SERVER] ' + argArray[0];
|
|
198
|
+
}
|
|
199
|
+
console.history.push({level: level, arguments: argArray});
|
|
200
|
+
};
|
|
201
|
+
});
|
|
206
202
|
JS
|
|
207
|
-
# rubocop:enable Layout/IndentHeredoc
|
|
208
203
|
end
|
|
209
204
|
|
|
210
205
|
private
|
|
@@ -5,6 +5,7 @@ module ReactOnRails
|
|
|
5
5
|
class EnsureAssetsCompiled
|
|
6
6
|
class << self
|
|
7
7
|
attr_accessor :has_been_run
|
|
8
|
+
|
|
8
9
|
@has_been_run = false
|
|
9
10
|
end
|
|
10
11
|
|
|
@@ -29,7 +30,7 @@ module ReactOnRails
|
|
|
29
30
|
# Be sure we don't do this again.
|
|
30
31
|
self.class.has_been_run = true
|
|
31
32
|
|
|
32
|
-
ReactOnRails::
|
|
33
|
+
ReactOnRails::Locales.compile
|
|
33
34
|
|
|
34
35
|
stale_gen_files = webpack_assets_status_checker.stale_generated_webpack_files
|
|
35
36
|
|
|
@@ -43,17 +44,15 @@ module ReactOnRails
|
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
def puts_start_compile_check_message(stale_files)
|
|
46
|
-
|
|
47
|
-
puts <<-MSG
|
|
47
|
+
puts <<~MSG
|
|
48
48
|
|
|
49
|
-
Detected the following stale generated files:
|
|
50
|
-
|
|
49
|
+
Detected the following stale generated files:
|
|
50
|
+
#{stale_files.join("\n ")}
|
|
51
51
|
|
|
52
|
-
React on Rails will ensure your JavaScript generated files are up to date, using your
|
|
53
|
-
`#{ReactOnRails::Utils.prepend_cd_node_modules_directory(ReactOnRails.configuration.build_test_command)}` command.
|
|
52
|
+
React on Rails will ensure your JavaScript generated files are up to date, using your
|
|
53
|
+
`#{ReactOnRails::Utils.prepend_cd_node_modules_directory(ReactOnRails.configuration.build_test_command)}` command.
|
|
54
54
|
|
|
55
55
|
MSG
|
|
56
|
-
# rubocop:enable Layout/IndentHeredoc
|
|
57
56
|
end
|
|
58
57
|
end
|
|
59
58
|
end
|
|
@@ -6,6 +6,23 @@ module ReactOnRails
|
|
|
6
6
|
module TestHelper
|
|
7
7
|
class WebpackAssetsCompiler
|
|
8
8
|
def compile_assets
|
|
9
|
+
if ReactOnRails.configuration.build_test_command.blank?
|
|
10
|
+
msg = <<~MSG
|
|
11
|
+
You are using the React on Rails test helper.
|
|
12
|
+
Either you used:
|
|
13
|
+
ReactOnRails::TestHelper.configure_rspec_to_compile_assets or
|
|
14
|
+
ReactOnRails::TestHelper.ensure_assets_compiled
|
|
15
|
+
but you did not specify the config.build_test_command
|
|
16
|
+
|
|
17
|
+
React on Rails is aborting your test run
|
|
18
|
+
|
|
19
|
+
If you wish to use the config/webpacker.yml compile option for tests
|
|
20
|
+
them remove your call to the ReactOnRails test helper.
|
|
21
|
+
MSG
|
|
22
|
+
puts Rainbow(msg).red
|
|
23
|
+
exit!(1)
|
|
24
|
+
end
|
|
25
|
+
|
|
9
26
|
puts "\nBuilding Webpack assets..."
|
|
10
27
|
|
|
11
28
|
cmd = ReactOnRails::Utils.prepend_cd_node_modules_directory(
|
data/lib/react_on_rails/utils.rb
CHANGED
|
@@ -8,7 +8,7 @@ require "active_support/core_ext/string"
|
|
|
8
8
|
|
|
9
9
|
module ReactOnRails
|
|
10
10
|
module Utils
|
|
11
|
-
TRUNCATION_FILLER = "\n... TRUNCATED ...\n"
|
|
11
|
+
TRUNCATION_FILLER = "\n... TRUNCATED ...\n"
|
|
12
12
|
|
|
13
13
|
# https://forum.shakacode.com/t/yak-of-the-week-ruby-2-4-pathname-empty-changed-to-look-at-file-size/901
|
|
14
14
|
# return object if truthy, else return nil
|
|
@@ -24,13 +24,12 @@ module ReactOnRails
|
|
|
24
24
|
# Pass in the msg and color as a symbol.
|
|
25
25
|
def self.wrap_message(msg, color = :red)
|
|
26
26
|
wrapper_line = ("=" * 80).to_s
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
#{
|
|
30
|
-
#{
|
|
31
|
-
#{wrapper_line}
|
|
27
|
+
fenced_msg = <<~MSG
|
|
28
|
+
#{wrapper_line}
|
|
29
|
+
#{msg.strip}
|
|
30
|
+
#{wrapper_line}
|
|
32
31
|
MSG
|
|
33
|
-
|
|
32
|
+
|
|
34
33
|
Rainbow(fenced_msg).color(color)
|
|
35
34
|
end
|
|
36
35
|
|
|
@@ -48,14 +47,13 @@ module ReactOnRails
|
|
|
48
47
|
unless status.success?
|
|
49
48
|
stdout_msg = stdout.present? ? "\nstdout:\n#{stdout.strip}\n" : ""
|
|
50
49
|
stderr_msg = stderr.present? ? "\nstderr:\n#{stderr.strip}\n" : ""
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
#{
|
|
55
|
-
|
|
56
|
-
exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
|
|
50
|
+
msg = <<~MSG
|
|
51
|
+
React on Rails FATAL ERROR!
|
|
52
|
+
#{failure_message}
|
|
53
|
+
cmd: #{cmd}
|
|
54
|
+
exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
|
|
57
55
|
MSG
|
|
58
|
-
|
|
56
|
+
|
|
59
57
|
puts wrap_message(msg)
|
|
60
58
|
|
|
61
59
|
# Rspec catches exit without! in the exit callbacks
|
|
@@ -72,11 +70,8 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
|
|
|
72
70
|
# Either:
|
|
73
71
|
# 1. Using same bundle for both server and client, so server bundle will be hashed in manifest
|
|
74
72
|
# 2. Using a different bundle (different Webpack config), so file is not hashed, and
|
|
75
|
-
# bundle_js_path will throw.
|
|
76
|
-
# 3. Not using webpacker, and
|
|
77
|
-
|
|
78
|
-
# Note, server bundle should not be in the manifest
|
|
79
|
-
# If using webpacker gem per https://github.com/rails/webpacker/issues/571
|
|
73
|
+
# bundle_js_path will throw so the default path is used without a hash.
|
|
74
|
+
# 3. Not using webpacker, and this method returns the bundle_js_file_path
|
|
80
75
|
return @server_bundle_path if @server_bundle_path && !Rails.env.development?
|
|
81
76
|
|
|
82
77
|
bundle_name = ReactOnRails.configuration.server_bundle_js_file
|
|
@@ -1,16 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ReactOnRails
|
|
2
4
|
module WebpackerUtils
|
|
3
5
|
def self.using_webpacker?
|
|
4
6
|
ReactOnRails::Utils.gem_available?("webpacker")
|
|
5
7
|
end
|
|
6
8
|
|
|
9
|
+
def self.webpacker_webpack_production_config_exists?
|
|
10
|
+
webpacker_webpack_config_abs_path = File.join(Rails.root,
|
|
11
|
+
"config/webpack/production.js")
|
|
12
|
+
File.exist?(webpacker_webpack_config_abs_path)
|
|
13
|
+
end
|
|
14
|
+
|
|
7
15
|
def self.dev_server_running?
|
|
8
16
|
return false unless using_webpacker?
|
|
9
17
|
|
|
10
18
|
Webpacker.dev_server.running?
|
|
11
19
|
end
|
|
12
20
|
|
|
13
|
-
# This returns either a URL for the webpack-dev-server
|
|
21
|
+
# This returns either a URL for the webpack-dev-server, non-server bundle or
|
|
22
|
+
# the hashed server bundle if using the same bundle for the client.
|
|
23
|
+
# Otherwise returns a file path.
|
|
14
24
|
def self.bundle_js_uri_from_webpacker(bundle_name)
|
|
15
25
|
# Note Webpacker 3.4.3 manifest lookup is inside of the public_output_path
|
|
16
26
|
# [2] (pry) ReactOnRails::WebpackerUtils: 0> Webpacker.manifest.lookup("app-bundle.js")
|
|
@@ -18,7 +28,14 @@ module ReactOnRails
|
|
|
18
28
|
# Next line will throw if the file or manifest does not exist
|
|
19
29
|
hashed_bundle_name = Webpacker.manifest.lookup!(bundle_name)
|
|
20
30
|
|
|
21
|
-
|
|
31
|
+
# support for hashing the server-bundle and having that built
|
|
32
|
+
# by a webpack watch process and not served by the webpack-dev-server, then we
|
|
33
|
+
# need an extra config value "same_bundle_for_client_and_server" where a value of false
|
|
34
|
+
# would mean that the bundle is created by a separate webpack watch process.
|
|
35
|
+
is_server_bundle = bundle_name == ReactOnRails.configuration.server_bundle_js_file
|
|
36
|
+
|
|
37
|
+
if Webpacker.dev_server.running? && (!is_server_bundle ||
|
|
38
|
+
ReactOnRails.configuration.same_bundle_for_client_and_server)
|
|
22
39
|
"#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}#{hashed_bundle_name}"
|
|
23
40
|
else
|
|
24
41
|
File.expand_path(File.join("public", hashed_bundle_name)).to_s
|
data/lib/react_on_rails.rb
CHANGED
|
@@ -22,4 +22,6 @@ require "react_on_rails/webpacker_utils"
|
|
|
22
22
|
require "react_on_rails/test_helper/webpack_assets_compiler"
|
|
23
23
|
require "react_on_rails/test_helper/webpack_assets_status_checker"
|
|
24
24
|
require "react_on_rails/test_helper/ensure_assets_compiled"
|
|
25
|
-
require "react_on_rails/
|
|
25
|
+
require "react_on_rails/locales/base"
|
|
26
|
+
require "react_on_rails/locales/to_js"
|
|
27
|
+
require "react_on_rails/locales/to_json"
|
data/lib/tasks/assets.rake
CHANGED
|
@@ -1,69 +1,56 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
# Important: The default assets:precompile is modified ONLY if the rails/webpacker webpack config
|
|
4
|
+
# does not exist!
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
namespace :react_on_rails do
|
|
8
|
-
namespace :assets do
|
|
9
|
-
desc "Creates non-digested symlinks for the assets in the public asset dir"
|
|
10
|
-
task symlink_non_digested_assets: :"assets:environment" do
|
|
11
|
-
ReactOnRails::AssetsPrecompile.new.symlink_non_digested_assets
|
|
12
|
-
end
|
|
6
|
+
require "active_support"
|
|
13
7
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ReactOnRails::AssetsPrecompile.new.delete_broken_symlinks
|
|
17
|
-
end
|
|
8
|
+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
|
|
9
|
+
ENV["NODE_ENV"] ||= "development"
|
|
18
10
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Otherwise Sprockets cannot find the files that webpack produces.
|
|
24
|
-
This is the secret sauce for how a Heroku deployment knows to create the webpack generated JavaScript files.
|
|
25
|
-
DESC
|
|
26
|
-
task compile_environment: :webpack do
|
|
27
|
-
Rake::Task["assets:environment"].invoke
|
|
28
|
-
end
|
|
11
|
+
unless ReactOnRails::WebpackerUtils.webpacker_webpack_production_config_exists?
|
|
12
|
+
# Ensure that rails/webpacker does not call bin/webpack if we're providing
|
|
13
|
+
# the build command.
|
|
14
|
+
ENV["WEBPACKER_PRECOMPILE"] = "false"
|
|
29
15
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
if Rake::Task.task_defined?("assets:precompile")
|
|
17
|
+
Rake::Task["assets:precompile"].enhance do
|
|
18
|
+
Rake::Task["react_on_rails:assets:webpack"].invoke
|
|
19
|
+
puts "Invoking task webpacker:clean from React on Rails"
|
|
20
|
+
Rake::Task["webpacker:clean"].invoke
|
|
34
21
|
end
|
|
22
|
+
else
|
|
23
|
+
Rake::Task.define_task("assets:precompile" => ["react_on_rails:assets:webpack",
|
|
24
|
+
"webpacker:clean"])
|
|
35
25
|
end
|
|
36
|
-
|
|
37
|
-
# These tasks run as pre-requisites of assets:precompile.
|
|
38
|
-
# Note, it's not possible to refer to ReactOnRails configuration values at this point.
|
|
39
|
-
Rake::Task["assets:precompile"]
|
|
40
|
-
.clear_prerequisites
|
|
41
|
-
.enhance([:environment, "react_on_rails:assets:compile_environment"])
|
|
42
|
-
.enhance do
|
|
43
|
-
Rake::Task["react_on_rails:assets:symlink_non_digested_assets"].invoke
|
|
44
|
-
Rake::Task["react_on_rails:assets:delete_broken_symlinks"].invoke
|
|
45
|
-
end
|
|
46
26
|
end
|
|
47
27
|
|
|
48
28
|
# Sprockets independent tasks
|
|
49
29
|
namespace :react_on_rails do
|
|
50
30
|
namespace :assets do
|
|
51
31
|
desc <<-DESC.strip_heredoc
|
|
52
|
-
Compile assets with webpack
|
|
53
|
-
Uses command defined with ReactOnRails.configuration.build_production_command
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
Compile assets with webpack
|
|
33
|
+
Uses command defined with ReactOnRails.configuration.build_production_command
|
|
34
|
+
sh "#{ReactOnRails::Utils.prepend_cd_node_modules_directory('<ReactOnRails.configuration.build_production_command>')}"
|
|
35
|
+
Note: This command is not automatically added to assets:precompile if the rails/webpacker
|
|
36
|
+
configuration file config/webpack/production.js exists.
|
|
56
37
|
DESC
|
|
57
38
|
task webpack: :locale do
|
|
58
|
-
if Rake::Task.task_defined?("webpacker:compile")
|
|
59
|
-
# TODO: Eventually, this will need reconsideration if we use any of the Webpacker compilation
|
|
60
|
-
Rake::Task["webpacker:compile"].clear
|
|
61
|
-
end
|
|
62
|
-
|
|
63
39
|
if ReactOnRails.configuration.build_production_command.present?
|
|
64
40
|
sh ReactOnRails::Utils.prepend_cd_node_modules_directory(
|
|
65
41
|
ReactOnRails.configuration.build_production_command
|
|
66
42
|
).to_s
|
|
43
|
+
else
|
|
44
|
+
msg = <<~MSG
|
|
45
|
+
React on Rails is aborting webpack compilation from task react_on_rails:assets:webpack
|
|
46
|
+
because you do not have the `config.build_production_command` defined.
|
|
47
|
+
|
|
48
|
+
Note, this task may have run as part of `assets:precompile`. If file
|
|
49
|
+
config/webpack/production.js does not exist, React on Rails will modify
|
|
50
|
+
the default `asset:precompile` to run task `react_on_rails:assets:webpack`.
|
|
51
|
+
MSG
|
|
52
|
+
puts Rainbow(msg).red
|
|
53
|
+
exit!(1)
|
|
67
54
|
end
|
|
68
55
|
end
|
|
69
56
|
end
|
data/lib/tasks/locale.rake
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "react_on_rails/
|
|
3
|
+
require "react_on_rails/locales/base"
|
|
4
|
+
require "react_on_rails/locales/to_js"
|
|
5
|
+
require "react_on_rails/locales/to_json"
|
|
4
6
|
require "active_support"
|
|
5
7
|
|
|
6
8
|
namespace :react_on_rails do
|
|
@@ -10,6 +12,6 @@ namespace :react_on_rails do
|
|
|
10
12
|
the "ReactOnRails.configuration.i18n_dir".
|
|
11
13
|
DESC
|
|
12
14
|
task locale: :environment do
|
|
13
|
-
ReactOnRails::
|
|
15
|
+
ReactOnRails::Locales.compile
|
|
14
16
|
end
|
|
15
17
|
end
|
data/package-scripts.yml
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
scripts:
|
|
2
2
|
lint:
|
|
3
|
-
description: Run all linters (eslint,
|
|
3
|
+
description: Run all linters (eslint, tsc)
|
|
4
4
|
script: concurrently --prefix "[{name}]" --names "ESLINT" -c "blue,yellow,magenta,orange" "nps eslint"
|
|
5
5
|
|
|
6
6
|
eslint:
|
|
7
7
|
default:
|
|
8
8
|
description: Run eslint.
|
|
9
|
-
script: eslint . --ext ".js,.jsx"
|
|
9
|
+
script: eslint . --ext ".js,.jsx,.ts"
|
|
10
10
|
fix:
|
|
11
11
|
description: Run eslint and auto-fix.
|
|
12
12
|
script: nps "eslint --fix"
|
|
@@ -17,30 +17,33 @@ scripts:
|
|
|
17
17
|
format:
|
|
18
18
|
default:
|
|
19
19
|
description: Format files using prettier.
|
|
20
|
-
script: concurrently --prefix "[{name}]" --names "js,json" -c "yellow,magenta,green" "nps format.js" "nps format.json"
|
|
20
|
+
script: concurrently --prefix "[{name}]" --names "ts,js,json" -c "yellow,magenta,green" "nps format.js" "nps format.json"
|
|
21
21
|
listDifferent:
|
|
22
22
|
description: Check that all files were formatted using prettier.
|
|
23
23
|
script: |
|
|
24
24
|
concurrently \
|
|
25
25
|
--prefix "[{name}]" \
|
|
26
|
-
--names "js,
|
|
27
|
-
-c "yellow,magenta
|
|
26
|
+
--names "ts,js,json" \
|
|
27
|
+
-c "yellow,magenta" \
|
|
28
28
|
"nps format.js.listDifferent" \
|
|
29
29
|
"nps format.json.listDifferent"
|
|
30
30
|
js:
|
|
31
31
|
default:
|
|
32
32
|
description: Run prettier-eslint on JS.
|
|
33
|
-
script: prettier "packages/**/*.@(js|jsx)" "spec/dummy/client/app/**/*.@(js|jsx)" "webpack.config.babel.js" "webpack/**/*.js" --write
|
|
33
|
+
#script: prettier "packages/**/*.@(js|jsx)" "spec/dummy/client/app/**/*.@(js|jsx)" "webpack.config.babel.js" "webpack/**/*.js" --write
|
|
34
|
+
script: prettier "**/*.@(js|jsx)" --write
|
|
34
35
|
listDifferent:
|
|
35
36
|
description: Check if any JS files would change by running prettier-eslint.
|
|
36
|
-
script: prettier "**/*.@(js|jsx)" "webpack.config.babel.js" "webpack/**/*.js" --list-different
|
|
37
|
+
# script: prettier "**/*.@(js|jsx)" "webpack.config.babel.js" "webpack/**/*.js" --list-different
|
|
38
|
+
script: prettier "**/*.@(js|jsx)" --list-different
|
|
37
39
|
json:
|
|
38
40
|
default:
|
|
39
41
|
description: Run prettier on JSON files.
|
|
40
42
|
script: rm -rf packages/vm-renderer/tests/tmp && prettier "**/*.json" --write
|
|
41
43
|
listDifferent:
|
|
42
44
|
description: Check if any JSON files would change by running prettier-eslint.
|
|
43
|
-
script: prettier "**/*.json"
|
|
45
|
+
script: prettier "**/*.json" --list-different
|
|
46
|
+
|
|
44
47
|
renderer:
|
|
45
48
|
description: Starts the node renderer.
|
|
46
49
|
script: node renderer.js
|