react_on_rails 5.2.0 → 6.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +31 -0
- data/PROJECTS.md +11 -2
- data/README.md +33 -203
- data/app/helpers/react_on_rails_helper.rb +32 -49
- data/docs/additional-reading/heroku-deployment.md +2 -35
- data/docs/additional-reading/node-server-rendering.md +30 -0
- data/docs/additional-reading/rails-assets.md +19 -0
- data/docs/additional-reading/rspec-configuration.md +38 -4
- data/docs/additional-reading/webpack-dev-server.md +16 -0
- data/docs/additional-reading/webpack.md +0 -10
- data/docs/api/javascript-api.md +37 -0
- data/docs/api/ruby-api-hot-reload-view-helpers.md +42 -0
- data/docs/api/ruby-api.md +3 -0
- data/docs/basics/generator.md +49 -0
- data/docs/{additional-reading → basics}/installation-overview.md +0 -0
- data/docs/basics/migrating-from-react-rails.md +17 -0
- data/docs/contributor-info/contributing.md +11 -0
- data/docs/{coding-style → contributor-info}/linters.md +0 -0
- data/lib/generators/USAGE +3 -95
- data/lib/generators/react_on_rails/base_generator.rb +10 -43
- data/lib/generators/react_on_rails/dev_tests_generator.rb +17 -1
- data/lib/generators/react_on_rails/install_generator.rb +0 -6
- data/lib/generators/react_on_rails/react_no_redux_generator.rb +3 -17
- data/lib/generators/react_on_rails/react_with_redux_generator.rb +4 -21
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +2 -2
- data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +3 -4
- data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx.tt +1 -11
- data/lib/generators/react_on_rails/templates/base/base/client/node/package.json +10 -0
- data/lib/generators/react_on_rails/templates/base/base/client/node/server.js +82 -0
- data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +3 -20
- data/lib/generators/react_on_rails/templates/base/base/client/webpack.config.js +58 -0
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt +60 -26
- data/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt +1 -4
- data/lib/generators/react_on_rails/templates/base/base/lib/tasks/load_test.rake +8 -0
- data/lib/generators/react_on_rails/templates/base/base/package.json.tt +0 -12
- data/lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb +1 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +1 -0
- data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +1 -7
- data/lib/generators/react_on_rails/templates/{base/base/client/app/bundles/HelloWorld/startup/clientRegistration.jsx.tt → no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx.tt} +7 -1
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/{HelloWorldAppClient.jsx.tt → HelloWorldApp.jsx.tt} +5 -1
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx +1 -5
- data/lib/react_on_rails.rb +2 -1
- data/lib/react_on_rails/configuration.rb +17 -5
- data/lib/react_on_rails/react_component/options.rb +76 -0
- data/lib/react_on_rails/server_rendering_pool.rb +9 -151
- data/lib/react_on_rails/server_rendering_pool/exec.rb +166 -0
- data/lib/react_on_rails/server_rendering_pool/node.rb +77 -0
- data/lib/react_on_rails/test_helper.rb +1 -6
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +4 -77
- data/lib/react_on_rails/test_helper/node_process_launcher.rb +12 -0
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +4 -28
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/tasks/assets.rake +115 -0
- data/package.json +2 -1
- data/rakelib/example_type.rb +3 -10
- data/rakelib/examples_config.yml +2 -2
- data/react_on_rails.gemspec +1 -0
- metadata +41 -20
- data/lib/generators/react_on_rails/templates/base/base/REACT_ON_RAILS.md +0 -16
- data/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md +0 -3
- data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js +0 -65
- data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js +0 -53
- data/lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverRegistration.jsx +0 -4
- data/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js +0 -39
- data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +0 -6
- data/lib/generators/react_on_rails/templates/no_redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +0 -6
- data/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js +0 -21
- data/lib/generators/react_on_rails/templates/redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +0 -19
- data/lib/react_on_rails/test_helper/webpack_process_checker.rb +0 -54
@@ -0,0 +1,77 @@
|
|
1
|
+
module ReactOnRails
|
2
|
+
module ServerRenderingPool
|
3
|
+
class Node
|
4
|
+
# This implementation of the rendering pool uses NodeJS to execute javasript code
|
5
|
+
def self.reset_pool
|
6
|
+
options = {
|
7
|
+
size: ReactOnRails.configuration.server_renderer_pool_size,
|
8
|
+
timeout: ReactOnRails.configuration.server_renderer_timeout
|
9
|
+
}
|
10
|
+
@js_context_pool = ConnectionPool.new(options) { create_js_context }
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.reset_pool_if_server_bundle_was_modified
|
14
|
+
# No need for this method, the server bundle is automatically reset by node when changes
|
15
|
+
# Empty implementation to conform to ServerRenderingPool interface
|
16
|
+
end
|
17
|
+
|
18
|
+
# js_code: JavaScript expression that returns a string.
|
19
|
+
# Returns a Hash:
|
20
|
+
# html: string of HTML for direct insertion on the page by evaluating js_code
|
21
|
+
# consoleReplayScript: script for replaying console
|
22
|
+
# hasErrors: true if server rendering errors
|
23
|
+
# Note, js_code does not have to be based on React.
|
24
|
+
# js_code MUST RETURN json stringify Object
|
25
|
+
# Calling code will probably call 'html_safe' on return value before rendering to the view.
|
26
|
+
def self.server_render_js_with_console_logging(js_code)
|
27
|
+
if trace_react_on_rails?
|
28
|
+
@file_index ||= 1
|
29
|
+
trace_messsage(js_code, "tmp/server-generated-#{@file_index % 10}.js")
|
30
|
+
@file_index += 1
|
31
|
+
end
|
32
|
+
json_string = eval_js(js_code)
|
33
|
+
JSON.parse(json_string)
|
34
|
+
end
|
35
|
+
|
36
|
+
class << self
|
37
|
+
private
|
38
|
+
|
39
|
+
def trace_messsage(js_code, file_name = "tmp/server-generated.js", force = false)
|
40
|
+
return unless trace_react_on_rails? || force
|
41
|
+
# Set to anything to print generated code.
|
42
|
+
puts "Z" * 80
|
43
|
+
puts "react_renderer.rb: 92"
|
44
|
+
puts "wrote file #{file_name}"
|
45
|
+
File.write(file_name, js_code)
|
46
|
+
puts "Z" * 80
|
47
|
+
end
|
48
|
+
|
49
|
+
def trace_react_on_rails?
|
50
|
+
ENV["TRACE_REACT_ON_RAILS"].present?
|
51
|
+
end
|
52
|
+
|
53
|
+
def eval_js(js_code)
|
54
|
+
max_int = (2**(32 - 2) - 1)
|
55
|
+
@js_context_pool.with do |js_context|
|
56
|
+
js_context.send(js_code, 0)
|
57
|
+
result = js_context.recv(max_int)
|
58
|
+
result
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_js_context
|
63
|
+
begin
|
64
|
+
client = UNIXSocket.new("client/node/node.sock")
|
65
|
+
client.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
|
66
|
+
rescue StandardError => e
|
67
|
+
Rails.logger.error("Unable to connect to socket: client/node/node.sock.
|
68
|
+
Make sure node server is up and running.")
|
69
|
+
Rails.logger.error(e)
|
70
|
+
raise e
|
71
|
+
end
|
72
|
+
client
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -44,8 +44,6 @@ module ReactOnRails
|
|
44
44
|
# Typical usage passes all params as nil defaults.
|
45
45
|
# webpack_assets_status_checker: provide: `up_to_date?`, `whats_not_up_to_date`, `client_dir`
|
46
46
|
# defaults to ReactOnRails::TestHelper::WebpackAssetsStatusChecker
|
47
|
-
# webpack_process_checker: provide one method: `def running?`
|
48
|
-
# defaults to ReactOnRails::TestHelper::WebpackProcessChecker
|
49
47
|
# webpack_assets_compiler: provide one method: `def compile`
|
50
48
|
# defaults to ReactOnRails::TestHelper::WebpackAssetsCompiler
|
51
49
|
# client_dir and generated_assets_dir are passed into the default webpack_assets_status_checker if you
|
@@ -54,7 +52,6 @@ module ReactOnRails
|
|
54
52
|
# webpack_generated_files in your configuration
|
55
53
|
def self.ensure_assets_compiled(webpack_assets_status_checker: nil,
|
56
54
|
webpack_assets_compiler: nil,
|
57
|
-
webpack_process_checker: nil,
|
58
55
|
client_dir: nil,
|
59
56
|
generated_assets_dir: nil,
|
60
57
|
webpack_generated_files: nil)
|
@@ -80,12 +77,10 @@ module ReactOnRails
|
|
80
77
|
end
|
81
78
|
|
82
79
|
webpack_assets_compiler ||= WebpackAssetsCompiler.new
|
83
|
-
webpack_process_checker ||= WebpackProcessChecker.new
|
84
80
|
|
85
81
|
ReactOnRails::TestHelper::EnsureAssetsCompiled.new(
|
86
82
|
webpack_assets_status_checker: webpack_assets_status_checker,
|
87
|
-
webpack_assets_compiler: webpack_assets_compiler
|
88
|
-
webpack_process_checker: webpack_process_checker
|
83
|
+
webpack_assets_compiler: webpack_assets_compiler
|
89
84
|
).call
|
90
85
|
end
|
91
86
|
end
|
@@ -1,31 +1,20 @@
|
|
1
1
|
module ReactOnRails
|
2
2
|
module TestHelper
|
3
3
|
class EnsureAssetsCompiled
|
4
|
-
SECONDS_TO_WAIT = 10
|
5
|
-
|
6
4
|
class << self
|
7
5
|
attr_accessor :has_been_run
|
8
6
|
@has_been_run = false
|
9
7
|
end
|
10
8
|
|
11
9
|
attr_reader :webpack_assets_status_checker,
|
12
|
-
:webpack_assets_compiler
|
13
|
-
:webpack_process_checker
|
14
|
-
|
15
|
-
MAX_TIME_TO_WAIT = 5
|
10
|
+
:webpack_assets_compiler
|
16
11
|
|
17
12
|
def initialize(webpack_assets_status_checker: nil,
|
18
|
-
webpack_assets_compiler: nil
|
19
|
-
webpack_process_checker: nil)
|
13
|
+
webpack_assets_compiler: nil)
|
20
14
|
@webpack_assets_status_checker = webpack_assets_status_checker
|
21
15
|
@webpack_assets_compiler = webpack_assets_compiler
|
22
|
-
@webpack_process_checker = webpack_process_checker
|
23
16
|
end
|
24
17
|
|
25
|
-
# rubocop:disable Metrics/AbcSize
|
26
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
27
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
28
|
-
|
29
18
|
# Several Scenarios:
|
30
19
|
# 1. No webpack watch processes for static assets and files are mising or out of date.
|
31
20
|
# 2. Only webpack watch process for server bundle as we're the hot reloading setup.
|
@@ -46,79 +35,17 @@ module ReactOnRails
|
|
46
35
|
# Inform the developer that we're ensuring gen assets are ready.
|
47
36
|
puts_start_compile_check_message(stale_gen_files)
|
48
37
|
|
49
|
-
|
50
|
-
client_running = webpack_process_checker.client_running?
|
51
|
-
server_running = webpack_process_checker.server_running?
|
52
|
-
already_compiled_client_file = false
|
53
|
-
|
54
|
-
# Check if running "hot" and not running a process to statically compile the client files.
|
55
|
-
if hot_running && !client_running
|
56
|
-
puts "Appears you're running hot reloading and are not rebuilding client files "\
|
57
|
-
"automatically. We'll try rebuilding only your client files first."
|
58
|
-
webpack_assets_compiler.compile_client(stale_gen_files)
|
59
|
-
already_compiled_client_file = true
|
60
|
-
|
61
|
-
stale_gen_files = webpack_assets_status_checker.stale_generated_webpack_files
|
62
|
-
|
63
|
-
# Return if we're all done!
|
64
|
-
return if stale_gen_files.empty?
|
65
|
-
end
|
66
|
-
|
67
|
-
loop_count = 0
|
68
|
-
if (already_compiled_client_file && server_running) ||
|
69
|
-
(!already_compiled_client_file && client_running)
|
70
|
-
puts "Waiting #{SECONDS_TO_WAIT} for webpack watch processes to compile files"
|
71
|
-
loop do
|
72
|
-
sleep 1
|
73
|
-
stale_gen_files = webpack_assets_status_checker.stale_generated_webpack_files
|
74
|
-
loop_count += 1
|
75
|
-
break if loop_count == SECONDS_TO_WAIT || stale_gen_files.empty?
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
final_compilation_check(already_compiled_client_file, client_running, server_running, stale_gen_files)
|
80
|
-
end
|
81
|
-
|
82
|
-
# rubocop:enable Metrics/AbcSize
|
83
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
84
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
85
|
-
|
86
|
-
def final_compilation_check(already_compiled_client_file, client_running, server_running, stale_gen_files)
|
87
|
-
return unless stale_gen_files.present?
|
88
|
-
if client_running || server_running
|
89
|
-
puts <<-MSG
|
90
|
-
Arghhhhhh! We still have the following stale generated files after waiting for Webpack to compile:
|
91
|
-
#{stale_gen_files.join("\n")}
|
92
|
-
|
93
|
-
This can happen if you removed the generated files after they've been created by your webpack
|
94
|
-
watch processes, such by running a clean on your generated bundles before starting your tests.
|
95
|
-
MSG
|
96
|
-
end
|
97
|
-
|
98
|
-
puts <<-MSG
|
99
|
-
|
100
|
-
If you are frequently running tests, you can run webpack in watch mode for static assets to
|
101
|
-
speed up this process. See the official documentation:
|
102
|
-
https://github.com/shakacode/react_on_rails/blob/master/docs/additional-reading/rspec-configuration.md
|
103
|
-
MSG
|
104
|
-
|
105
|
-
if already_compiled_client_file
|
106
|
-
# So only do serer file
|
107
|
-
webpack_assets_compiler.compile_server(stale_gen_files)
|
108
|
-
else
|
109
|
-
webpack_assets_compiler.compile_as_necessary(stale_gen_files)
|
110
|
-
end
|
38
|
+
webpack_assets_compiler.compile_assets
|
111
39
|
end
|
112
40
|
|
113
41
|
def puts_start_compile_check_message(stale_files)
|
114
|
-
server_msg = Utils.server_rendering_is_enabled? ? "and `build:server`" : ""
|
115
42
|
puts <<-MSG
|
116
43
|
|
117
44
|
Detected are the following stale generated files:
|
118
45
|
#{stale_files.join("\n")}
|
119
46
|
|
120
47
|
React on Rails will ensure your JavaScript generated files are up to date, using your
|
121
|
-
|
48
|
+
/client level package.json `build:test` command.
|
122
49
|
|
123
50
|
MSG
|
124
51
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ReactOnRails
|
2
|
+
module TestHelper
|
3
|
+
def self.launch_node
|
4
|
+
if ReactOnRails.configuration.server_render_method == "NodeJS"
|
5
|
+
path = "#{::Rails.root}/client/node"
|
6
|
+
puts "Launching NodeJS server at #{path}"
|
7
|
+
system("cd #{path} && npm start &")
|
8
|
+
sleep(1)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -3,38 +3,14 @@
|
|
3
3
|
module ReactOnRails
|
4
4
|
module TestHelper
|
5
5
|
class WebpackAssetsCompiler
|
6
|
-
def
|
7
|
-
|
8
|
-
compile_server(stale_files)
|
9
|
-
end
|
10
|
-
|
11
|
-
def compile_client(stale_files)
|
12
|
-
compile_type(:client) if needs_client_compile?(stale_files)
|
13
|
-
end
|
14
|
-
|
15
|
-
def compile_server(stale_files)
|
16
|
-
compile_type(:server) if needs_server_compile?(stale_files)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
6
|
+
def compile_assets
|
7
|
+
puts "\nBuilding Webpack assets..."
|
20
8
|
|
21
|
-
|
22
|
-
puts "\nBuilding Webpack #{type}-rendering assets..."
|
23
|
-
|
24
|
-
build_output = `cd client && npm run build:#{type}`
|
9
|
+
build_output = `cd client && #{ReactOnRails.configuration.npm_build_test_command}`
|
25
10
|
|
26
11
|
raise "Error in building assets!\n#{build_output}" unless Utils.last_process_completed_successfully?
|
27
12
|
|
28
|
-
puts "Completed building Webpack
|
29
|
-
end
|
30
|
-
|
31
|
-
def needs_client_compile?(stale_files)
|
32
|
-
!stale_files.all? { |name| name.include?("server") }
|
33
|
-
end
|
34
|
-
|
35
|
-
def needs_server_compile?(stale_files)
|
36
|
-
return false unless Utils.server_rendering_is_enabled?
|
37
|
-
stale_files.any? { |name| name.include?("server") }
|
13
|
+
puts "Completed building Webpack assets."
|
38
14
|
end
|
39
15
|
end
|
40
16
|
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module ReactOnRails
|
2
|
+
class << self
|
3
|
+
def assets_path
|
4
|
+
dir = File.join(Rails.configuration.paths['public'].first,
|
5
|
+
Rails.configuration.assets.prefix)
|
6
|
+
Pathname.new(dir)
|
7
|
+
end
|
8
|
+
|
9
|
+
def symlink_file(target, symlink)
|
10
|
+
if not File.exist?(symlink) or File.lstat(symlink).symlink?
|
11
|
+
if File.exist?(target)
|
12
|
+
puts "React On Rails: Symlinking #{target} to #{symlink}"
|
13
|
+
FileUtils.ln_s target, symlink, force: true
|
14
|
+
end
|
15
|
+
else
|
16
|
+
puts "React On Rails: File #{symlink} already exists. Failed to symlink #{target}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
namespace :react_on_rails do
|
23
|
+
namespace :assets do
|
24
|
+
|
25
|
+
if ReactOnRails.configuration.symlink_non_digested_assets_regex
|
26
|
+
desc "Creates non-digested symlinks for the assets in the public asset dir"
|
27
|
+
task symlink_non_digested_assets: :"assets:environment" do
|
28
|
+
manifest_path = Dir.glob(ReactOnRails::assets_path.join(".sprockets-manifest-*.json"))
|
29
|
+
.first
|
30
|
+
manifest_data = JSON.load(File.new(manifest_path))
|
31
|
+
|
32
|
+
manifest_data["assets"].each do |logical_path, digested_path|
|
33
|
+
regex = ReactOnRails.configuration.symlink_non_digested_assets_regex
|
34
|
+
if logical_path =~ regex
|
35
|
+
full_digested_path = ReactOnRails::assets_path.join(digested_path)
|
36
|
+
full_nondigested_path = ReactOnRails::assets_path.join(logical_path)
|
37
|
+
extension = full_digested_path.extname
|
38
|
+
full_digested_gz_path = full_digested_path.sub_ext("#{extension}.gz")
|
39
|
+
full_nondigested_gz_path = full_nondigested_path.sub_ext("#{extension}.gz")
|
40
|
+
ReactOnRails::symlink_file(full_digested_path, full_nondigested_path)
|
41
|
+
ReactOnRails::symlink_file(full_digested_gz_path, full_nondigested_gz_path)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Cleans all broken symlinks for the assets in the public asset dir"
|
47
|
+
task delete_broken_symlinks: :"assets:environment" do
|
48
|
+
Dir.glob(ReactOnRails::assets_path.join("*")).each do |filename|
|
49
|
+
if File.lstat(filename).symlink?
|
50
|
+
begin
|
51
|
+
target = File.readlink(filename)
|
52
|
+
rescue
|
53
|
+
puts "React on Rails: Warning: your platform doesn't support File::readlink method."/
|
54
|
+
"Skipping broken link check."
|
55
|
+
return
|
56
|
+
end
|
57
|
+
path = Pathname.new(File.dirname(filename))
|
58
|
+
target_path = path.join(target)
|
59
|
+
unless File.exist?(target_path)
|
60
|
+
puts "React on Rails: Deleting broken link: #{filename}"
|
61
|
+
File.delete(filename)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# We might need the clear_prerequisites (delete after testing without)
|
70
|
+
# Rake::Task["assets:precompile"]
|
71
|
+
# .clear_prerequisites
|
72
|
+
# .enhance(["assets:compile_environment"])
|
73
|
+
|
74
|
+
if ReactOnRails.configuration.npm_build_production_command.present?
|
75
|
+
# In this task, set prerequisites for the assets:precompile task
|
76
|
+
desc <<-DESC
|
77
|
+
Create webpack assets before calling assets:environment
|
78
|
+
The webpack task must run before assets:environment task.
|
79
|
+
Otherwise Sprockets cannot find the files that webpack produces.
|
80
|
+
This is the secret sauce for how a Heroku deployment knows to create the webpack generated JavaScript files.
|
81
|
+
DESC
|
82
|
+
task compile_environment: :webpack do
|
83
|
+
Rake::Task["assets:environment"].invoke
|
84
|
+
end
|
85
|
+
|
86
|
+
desc <<-DESC
|
87
|
+
Compile assets with webpack
|
88
|
+
Uses command defined with ReactOnRails.configuration.npm_build_production_command
|
89
|
+
sh "cd client && #{ReactOnRails.configuration.npm_build_production_command}"
|
90
|
+
DESC
|
91
|
+
task :webpack do
|
92
|
+
sh "cd client && #{ReactOnRails.configuration.npm_build_production_command}"
|
93
|
+
end
|
94
|
+
|
95
|
+
desc "Delete assets created with webpack, in #{ReactOnRails.configuration.generated_assets_dir}"
|
96
|
+
task :clobber do
|
97
|
+
rm_r Dir.glob(Rails.root.join("#{ReactOnRails.configuration.generated_assets_dir}/*"))
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
if ReactOnRails.configuration.symlink_non_digested_assets_regex
|
104
|
+
Rake::Task["assets:precompile"].enhance do
|
105
|
+
Rake::Task["react_on_rails:assets:symlink_non_digested_assets"].invoke
|
106
|
+
Rake::Task["react_on_rails:assets:delete_broken_symlinks"].invoke
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
if ReactOnRails.configuration.npm_build_production_command.present?
|
111
|
+
Rake::Task["assets:precompile"].enhance do
|
112
|
+
Rake::Task["react_on_rails:assets:compile_environment"].invoke
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-on-rails",
|
3
|
-
"version": "
|
3
|
+
"version": "6.0.0-beta.1",
|
4
4
|
"description": "react-on-rails JavaScript for react_on_rails Ruby gem",
|
5
5
|
"main": "node_package/lib/ReactOnRails.js",
|
6
6
|
"directories": {
|
@@ -15,6 +15,7 @@
|
|
15
15
|
"babel-preset-es2015": "^6.6.0",
|
16
16
|
"babel-preset-react": "^6.5.0",
|
17
17
|
"babel-preset-stage-0": "^6.5.0",
|
18
|
+
"babel-runtime": "^6.6.1",
|
18
19
|
"babel-tape-runner": "^2.0.1",
|
19
20
|
"babel-types": "^6.7.2",
|
20
21
|
"babelify": "^7.2.0",
|
data/rakelib/example_type.rb
CHANGED
@@ -28,10 +28,6 @@ module ReactOnRails
|
|
28
28
|
"#{@name} example app"
|
29
29
|
end
|
30
30
|
|
31
|
-
def server_rendering?
|
32
|
-
generator_options.include?("--server-rendering")
|
33
|
-
end
|
34
|
-
|
35
31
|
def dir
|
36
32
|
File.join(examples_dir, name)
|
37
33
|
end
|
@@ -53,14 +49,12 @@ module ReactOnRails
|
|
53
49
|
end
|
54
50
|
|
55
51
|
def webpack_bundles_dir
|
56
|
-
File.join(dir, "app", "assets", "javascripts", "
|
52
|
+
File.join(dir, "app", "assets", "javascripts", "webpack")
|
57
53
|
end
|
58
54
|
|
59
55
|
def webpack_bundles
|
60
56
|
bundles = []
|
61
|
-
bundles << File.join(webpack_bundles_dir, "
|
62
|
-
bundles << File.join(webpack_bundles_dir, "server-bundle.js") if server_rendering?
|
63
|
-
bundles << File.join(webpack_bundles_dir, "vendor-bundle.js")
|
57
|
+
bundles << File.join(webpack_bundles_dir, "webpack-bundle.js")
|
64
58
|
end
|
65
59
|
|
66
60
|
def gemfile
|
@@ -137,8 +131,7 @@ module ReactOnRails
|
|
137
131
|
def build_webpack_bundles_shell_commands
|
138
132
|
webpack_command = File.join("$(npm bin)", "webpack")
|
139
133
|
shell_commands = []
|
140
|
-
shell_commands << "#{webpack_command} --config webpack.
|
141
|
-
shell_commands << "#{webpack_command} --config webpack.client.rails.config.js"
|
134
|
+
shell_commands << "#{webpack_command} --config webpack.config.js"
|
142
135
|
end
|
143
136
|
|
144
137
|
# Assumes we are inside a rails app's folder and necessary gems have been installed
|