react_on_rails 8.0.2 → 9.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/.eslintignore +2 -0
- data/.gitignore +2 -2
- data/.rubocop.yml +5 -0
- data/.travis.yml +12 -1
- data/CHANGELOG.md +185 -6
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +6 -2
- data/Gemfile.rails32 +74 -0
- data/KUDOS.md +5 -0
- data/README.md +200 -84
- data/Rakefile +11 -1
- data/app/helpers/react_on_rails_helper.rb +1 -1
- data/docs/additional-reading/asset-pipeline.md +20 -0
- data/docs/additional-reading/hot-reloading-rails-development.md +4 -75
- data/docs/additional-reading/node-server-rendering.md +2 -166
- data/docs/additional-reading/rails-assets-relative-paths.md +3 -1
- data/docs/additional-reading/rails-engine-integration.md +1 -1
- data/docs/additional-reading/rspec-configuration.md +7 -24
- data/docs/api/ruby-api-hot-reload-view-helpers.md +2 -2
- data/{lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt → docs/basics/configuration.md} +80 -41
- data/docs/basics/generator.md +0 -5
- data/docs/basics/installation-overview.md +6 -5
- data/docs/contributor-info/generator-testing.md +0 -9
- data/docs/tutorial.md +31 -34
- data/lib/generators/USAGE +0 -4
- data/lib/generators/react_on_rails/base_generator.rb +43 -76
- data/lib/generators/react_on_rails/dev_tests_generator.rb +7 -5
- data/lib/generators/react_on_rails/install_generator.rb +5 -10
- data/lib/generators/react_on_rails/react_no_redux_generator.rb +10 -9
- data/lib/generators/react_on_rails/react_with_redux_generator.rb +27 -17
- data/lib/generators/react_on_rails/templates/.eslintrc +2 -0
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +4 -0
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +5 -0
- data/lib/generators/react_on_rails/templates/base/base/{client/app → app/javascript}/bundles/HelloWorld/components/HelloWorld.jsx +1 -2
- data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +0 -1
- data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +12 -0
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +41 -0
- data/lib/generators/react_on_rails/templates/dev_tests/.eslintrc +25 -0
- data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +0 -1
- 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/spec_helper.rb +2 -0
- data/lib/generators/react_on_rails/templates/redux/base/{client/app → app/javascript}/bundles/HelloWorld/startup/HelloWorldApp.jsx +1 -3
- data/lib/react_on_rails/configuration.rb +21 -16
- data/lib/react_on_rails/git_utils.rb +9 -3
- data/lib/react_on_rails/prerender_error.rb +15 -9
- data/lib/react_on_rails/server_rendering_pool/exec.rb +21 -8
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +1 -1
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +3 -1
- data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +12 -8
- data/lib/react_on_rails/test_helper.rb +7 -6
- data/lib/react_on_rails/utils.rb +77 -16
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/version_checker.rb +2 -1
- data/lib/tasks/assets.rake +12 -4
- data/package.json +25 -21
- data/rakelib/dummy_apps.rake +9 -0
- data/rakelib/example_type.rb +4 -70
- data/rakelib/examples.rake +5 -55
- data/rakelib/node_package.rake +1 -0
- data/rakelib/release.rake +9 -1
- data/rakelib/run_rspec.rake +24 -5
- data/react_on_rails.gemspec +2 -1
- data/webpackConfigLoader.js +45 -72
- data/yarn.lock +638 -252
- metadata +36 -26
- data/lib/generators/react_on_rails/node_generator.rb +0 -24
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +0 -2
- data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb.tt +0 -15
- data/lib/generators/react_on_rails/templates/base/base/client/.babelrc +0 -3
- data/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md +0 -9
- data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +0 -36
- data/lib/generators/react_on_rails/templates/base/base/client/webpack.config.js +0 -77
- data/lib/generators/react_on_rails/templates/base/base/config/webpacker_lite.yml +0 -27
- data/lib/generators/react_on_rails/templates/base/base/package.json.tt +0 -8
- data/lib/generators/react_on_rails/templates/node/base/client/node/package.json +0 -10
- data/lib/generators/react_on_rails/templates/node/base/client/node/server.js +0 -105
- /data/lib/generators/react_on_rails/templates/base/base/{client/app/bundles/HelloWorld/startup/registration.jsx.tt → app/javascript/packs/registration.js.tt} +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/{client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx → app/javascript/bundles/HelloWorld/actions/helloWorldActionCreators.js} +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/{client/app → app/javascript}/bundles/HelloWorld/components/HelloWorld.jsx +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/{client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx → app/javascript/bundles/HelloWorld/constants/helloWorldConstants.js} +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/{client/app/bundles/HelloWorld/containers/HelloWorldContainer.jsx → app/javascript/bundles/HelloWorld/containers/HelloWorldContainer.js} +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/{client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx → app/javascript/bundles/HelloWorld/reducers/helloWorldReducer.js} +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/{client/app/bundles/HelloWorld/store/helloWorldStore.jsx → app/javascript/bundles/HelloWorld/store/helloWorldStore.js} +0 -0
data/rakelib/example_type.rb
CHANGED
|
@@ -38,51 +38,23 @@ module ReactOnRails
|
|
|
38
38
|
Dir.exist?(dir)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
def client_dir
|
|
42
|
-
File.join(dir, "client")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def source_package_json
|
|
46
|
-
File.join(gem_root, "lib/generators/react_on_rails/templates/base/base/client/package.json.tt")
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def node_modules_dir
|
|
50
|
-
File.join(client_dir, "node_modules")
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def webpack_bundles_dir
|
|
54
|
-
File.join(dir, "public", "webpack", "test")
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def webpack_bundles
|
|
58
|
-
bundles = []
|
|
59
|
-
bundles << File.join(webpack_bundles_dir, "webpack-bundle.js")
|
|
60
|
-
end
|
|
61
|
-
|
|
62
41
|
def gemfile
|
|
63
42
|
File.join(dir, "Gemfile")
|
|
64
43
|
end
|
|
65
44
|
|
|
66
|
-
def gemfile_lock
|
|
67
|
-
"#{gemfile}.lock"
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def package_json
|
|
71
|
-
File.join(client_dir, "package.json")
|
|
72
|
-
end
|
|
73
|
-
|
|
74
45
|
# Gems we need to add to the Gemfile before bundle installing
|
|
75
46
|
def required_gems
|
|
76
47
|
relative_gem_root = Pathname(gem_root).relative_path_from(Pathname(dir))
|
|
77
48
|
["gem 'react_on_rails', path: '#{relative_gem_root}'"]
|
|
78
49
|
end
|
|
79
50
|
|
|
80
|
-
# Options we pass when running `rails new` from the command-line
|
|
51
|
+
# Options we pass when running `rails new` from the command-line.
|
|
52
|
+
# The webpack=react option is key.
|
|
81
53
|
def rails_options
|
|
82
|
-
"--skip-bundle --skip-spring --skip-git --skip-test-unit --skip-active-record"
|
|
54
|
+
"--skip-bundle --skip-spring --skip-git --skip-test-unit --skip-active-record --webpack=react"
|
|
83
55
|
end
|
|
84
56
|
|
|
85
|
-
%w[gen
|
|
57
|
+
%w[gen clobber npm_install build_webpack_bundles].each do |task_type|
|
|
86
58
|
method_name_normal = "#{task_type}_task_name" # ex: `clean_task_name`
|
|
87
59
|
method_name_short = "#{method_name_normal}_short" # ex: `clean_task_name_short`
|
|
88
60
|
|
|
@@ -98,44 +70,6 @@ module ReactOnRails
|
|
|
98
70
|
"run_rspec:#{rspec_task_name_short}"
|
|
99
71
|
end
|
|
100
72
|
|
|
101
|
-
def source_files
|
|
102
|
-
FileList.new(all_files_in_dir(generators_source_dir))
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
# Note: we need to explicitly declare a file we know is supposed to be there
|
|
106
|
-
# to indicate that the example is in need of being rebuilt in the case of its absence.
|
|
107
|
-
def generated_files
|
|
108
|
-
FileList.new(all_files_in_dir(dir)) do |fl|
|
|
109
|
-
fl.include(gemfile) # explicitly declared file (dependency of Gemfile.lock)
|
|
110
|
-
fl.include(package_json) # explicitly declared file (dependency of NPM Install)
|
|
111
|
-
fl.exclude(%r{client(/node_modules(.+)?)?$}) # leave node_modules folder
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def generated_client_files
|
|
116
|
-
generated_files.exclude { |f| !f.start_with?(client_dir) }
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
# generated files plus explicitly included files resulting from running
|
|
120
|
-
# bundle install, yarn, and generating the webpack bundles
|
|
121
|
-
def prepared_files
|
|
122
|
-
generated_files
|
|
123
|
-
.include(webpack_bundles)
|
|
124
|
-
.include(node_modules_dir)
|
|
125
|
-
.include(gemfile_lock)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def clean_files
|
|
129
|
-
generated_files
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
# Assumes we are inside client folder
|
|
133
|
-
def build_webpack_bundles_shell_commands
|
|
134
|
-
webpack_command = File.join("$(yarn bin)", "webpack")
|
|
135
|
-
shell_commands = []
|
|
136
|
-
shell_commands << "NODE_ENV=test #{webpack_command} --config webpack.config.js"
|
|
137
|
-
end
|
|
138
|
-
|
|
139
73
|
# Assumes we are inside a rails app's folder and necessary gems have been installed
|
|
140
74
|
def generator_shell_commands
|
|
141
75
|
shell_commands = []
|
data/rakelib/examples.rake
CHANGED
|
@@ -9,8 +9,6 @@ require "yaml"
|
|
|
9
9
|
require_relative "example_type"
|
|
10
10
|
require_relative "task_helpers"
|
|
11
11
|
include ReactOnRails::TaskHelpers
|
|
12
|
-
|
|
13
|
-
# rubocop:disable Metrics/BlockLength
|
|
14
12
|
namespace :examples do
|
|
15
13
|
# Loads data from examples_config.yml and instantiates corresponding ExampleType objects
|
|
16
14
|
examples_config_file = File.expand_path("../examples_config.yml", __FILE__)
|
|
@@ -19,43 +17,6 @@ namespace :examples do
|
|
|
19
17
|
|
|
20
18
|
# Define tasks for each example type
|
|
21
19
|
ExampleType.all.each do |example_type|
|
|
22
|
-
# GENERATED FILES
|
|
23
|
-
example_type.generated_files.each do |f|
|
|
24
|
-
file f => example_type.source_files do
|
|
25
|
-
Rake::Task[example_type.gen_task_name].invoke
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# GEMFILE.LOCK
|
|
30
|
-
file example_type.gemfile_lock => example_type.gemfile do
|
|
31
|
-
bundle_install_in(example_type.dir)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# WEBPACK BUNDLES
|
|
35
|
-
example_type.webpack_bundles.each do |f|
|
|
36
|
-
file f => example_type.generated_client_files do
|
|
37
|
-
Rake::Task[example_type.build_webpack_bundles_task_name].invoke
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# BUILD WEBPACK BUNDLES
|
|
42
|
-
task example_type.build_webpack_bundles_task_name_short => example_type.npm_install_task_name do
|
|
43
|
-
sh_in_dir(example_type.client_dir, example_type.build_webpack_bundles_shell_commands)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# YARN INSTALL
|
|
47
|
-
task example_type.npm_install_task_name_short => example_type.package_json do
|
|
48
|
-
unless uptodate?(example_type.node_modules_dir, [example_type.source_package_json])
|
|
49
|
-
sh_in_dir(example_type.client_dir, "yarn install --mutex network")
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# CLEAN
|
|
54
|
-
desc "Cleans #{example_type.name_pretty}"
|
|
55
|
-
task example_type.clean_task_name_short do
|
|
56
|
-
example_type.clean_files.each { |f| rm_rf(f) }
|
|
57
|
-
end
|
|
58
|
-
|
|
59
20
|
# CLOBBER
|
|
60
21
|
desc "Clobbers (deletes) #{example_type.name_pretty}"
|
|
61
22
|
task example_type.clobber_task_name_short do
|
|
@@ -64,39 +25,28 @@ namespace :examples do
|
|
|
64
25
|
|
|
65
26
|
# GENERATE
|
|
66
27
|
desc "Generates #{example_type.name_pretty}"
|
|
67
|
-
task example_type.gen_task_name_short => example_type.
|
|
28
|
+
task example_type.gen_task_name_short => example_type.clobber_task_name do
|
|
68
29
|
mkdir_p(example_type.dir)
|
|
69
30
|
sh_in_dir(examples_dir, "rails new #{example_type.name} #{example_type.rails_options}")
|
|
70
31
|
sh_in_dir(example_type.dir, "touch .gitignore")
|
|
71
32
|
append_to_gemfile(example_type.gemfile, example_type.required_gems)
|
|
72
33
|
bundle_install_in(example_type.dir)
|
|
73
34
|
sh_in_dir(example_type.dir, example_type.generator_shell_commands)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
# PREPARE
|
|
77
|
-
desc "Prepares #{example_type.name_pretty} (generates example, `yarn`s, and generates webpack bundles)"
|
|
78
|
-
multitask example_type.prepare_task_name_short => example_type.prepared_files do
|
|
79
|
-
Rake::Task["node_package"].invoke
|
|
35
|
+
sh_in_dir(example_type.dir, "yarn")
|
|
80
36
|
end
|
|
81
37
|
end
|
|
82
38
|
|
|
83
|
-
desc "Cleans all example apps"
|
|
84
|
-
multitask clean: ExampleType.all.map(&:clean_task_name)
|
|
85
|
-
|
|
86
39
|
desc "Clobbers (deletes) all example apps"
|
|
87
40
|
task :clobber do
|
|
88
41
|
rm_rf(examples_dir)
|
|
89
42
|
end
|
|
90
43
|
|
|
91
44
|
desc "Generates all example apps"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
desc "Prepares all example apps"
|
|
95
|
-
multitask prepare_all: ExampleType.all.map(&:prepare_task_name)
|
|
45
|
+
task gen_all: ExampleType.all.map(&:gen_task_name)
|
|
96
46
|
end
|
|
97
47
|
|
|
98
|
-
desc "
|
|
99
|
-
|
|
48
|
+
desc "Generates all example apps. Run `rake -D examples` to see all available options"
|
|
49
|
+
task examples: ["examples:gen_all"]
|
|
100
50
|
|
|
101
51
|
private
|
|
102
52
|
|
data/rakelib/node_package.rake
CHANGED
data/rakelib/release.rake
CHANGED
|
@@ -22,6 +22,7 @@ which are installed via `bundle install` and `yarn`
|
|
|
22
22
|
|
|
23
23
|
Example: `rake release[2.1.0,false]`")
|
|
24
24
|
|
|
25
|
+
# rubocop:disable Metrics/BlockLength
|
|
25
26
|
task :release, %i[gem_version dry_run tools_install] do |_t, args|
|
|
26
27
|
class MessageHandler
|
|
27
28
|
def add_error(error)
|
|
@@ -65,5 +66,12 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
|
|
|
65
66
|
sh_in_dir(gem_root, release_it_command)
|
|
66
67
|
|
|
67
68
|
# Release the new gem version
|
|
68
|
-
|
|
69
|
+
unless is_dry_run
|
|
70
|
+
sh_in_dir(gem_root, "gem release")
|
|
71
|
+
|
|
72
|
+
# Update master with new npm version
|
|
73
|
+
sh_in_dir(File.join(gem_root, "spec", "dummy", "client"), "yarn add react-on-rails@#{npm_version}")
|
|
74
|
+
sh_in_dir(gem_root, "git commit -am 'Updated spec/dummy/client/package.json latest version'")
|
|
75
|
+
sh_in_dir(gem_root, "git push")
|
|
76
|
+
end
|
|
69
77
|
end
|
data/rakelib/run_rspec.rake
CHANGED
|
@@ -18,6 +18,16 @@ namespace :run_rspec do
|
|
|
18
18
|
run_tests_in("", rspec_args: File.join("spec", "react_on_rails"))
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
desc "Run RSpec with rails32 gemfile"
|
|
22
|
+
task :gem_rails32 do
|
|
23
|
+
rspec_args = "spec/react_on_rails --exclude-pattern "\
|
|
24
|
+
"\"**/generators/*_spec.rb,**/utils_spec.rb,"\
|
|
25
|
+
"**/webpack_assets_status_checker_spec.rb,**/test_helper/*_spec.rb\""
|
|
26
|
+
run_tests_in("",
|
|
27
|
+
rspec_args: rspec_args,
|
|
28
|
+
env_vars: "BUNDLE_GEMFILE=spec/dummy_no_webpacker/Gemfile.rails32")
|
|
29
|
+
end
|
|
30
|
+
|
|
21
31
|
desc "Runs dummy rspec with turbolinks"
|
|
22
32
|
task dummy: ["dummy_apps:dummy_app"] do
|
|
23
33
|
clean_gen_assets(spec_dummy_dir)
|
|
@@ -34,22 +44,30 @@ namespace :run_rspec do
|
|
|
34
44
|
command_name: "dummy_no_turbolinks")
|
|
35
45
|
end
|
|
36
46
|
|
|
47
|
+
desc "Runs dummy_no_webpacker rspec"
|
|
48
|
+
task :dummy_no_webpacker do
|
|
49
|
+
dummy_app_dir = File.join(gem_root, "spec/dummy_no_webpacker")
|
|
50
|
+
clean_gen_assets(dummy_app_dir)
|
|
51
|
+
run_tests_in(dummy_app_dir,
|
|
52
|
+
env_vars: "BUNDLE_GEMFILE=Gemfile.rails32")
|
|
53
|
+
end
|
|
54
|
+
|
|
37
55
|
# Dynamically define Rake tasks for each example app found in the examples directory
|
|
38
56
|
ExampleType.all.each do |example_type|
|
|
39
57
|
desc "Runs RSpec for #{example_type.name_pretty} only"
|
|
40
|
-
task example_type.rspec_task_name_short => example_type.
|
|
58
|
+
task example_type.rspec_task_name_short => example_type.gen_task_name do
|
|
41
59
|
run_tests_in(File.join(examples_dir, example_type.name)) # have to use relative path
|
|
42
60
|
end
|
|
43
61
|
end
|
|
44
62
|
|
|
45
63
|
desc "Runs Rspec for example apps only"
|
|
46
|
-
task examples: "examples:
|
|
64
|
+
task examples: "examples:gen_all" do
|
|
47
65
|
ExampleType.all.each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
|
|
48
66
|
end
|
|
49
67
|
|
|
50
68
|
desc "(HACK) Run RSpec on spec/empty_spec in order to have SimpleCov generate a coverage report from cache"
|
|
51
69
|
task :empty do
|
|
52
|
-
sh %(COVERAGE=true rspec spec/empty_spec.rb)
|
|
70
|
+
sh %(#{ENV['USE_COVERALLS'] ? 'COVERAGE=true' : ''} rspec spec/empty_spec.rb)
|
|
53
71
|
end
|
|
54
72
|
|
|
55
73
|
Coveralls::RakeTask.new if ENV["USE_COVERALLS"] == "TRUE"
|
|
@@ -70,7 +88,7 @@ task :js_tests do
|
|
|
70
88
|
sh "yarn run test"
|
|
71
89
|
end
|
|
72
90
|
|
|
73
|
-
msg =
|
|
91
|
+
msg = <<-DESC.strip_heredoc
|
|
74
92
|
Runs all tests, run `rake -D run_rspec` to see all available test options.
|
|
75
93
|
"rake run_rspec:example_basic" is a good way to run only one generator test.
|
|
76
94
|
DESC
|
|
@@ -101,7 +119,8 @@ def run_tests_in(dir, options = {})
|
|
|
101
119
|
|
|
102
120
|
command_name = options.fetch(:command_name, path.basename)
|
|
103
121
|
rspec_args = options.fetch(:rspec_args, "")
|
|
104
|
-
env_vars = %(#{options.fetch(:env_vars, '')}
|
|
122
|
+
env_vars = %(#{options.fetch(:env_vars, '')} TEST_ENV_COMMAND_NAME="#{command_name}").dup
|
|
123
|
+
env_vars << "COVERAGE=true" if ENV["USE_COVERALLS"]
|
|
105
124
|
sh_in_dir(path.realpath, "#{env_vars} bundle exec rspec #{rspec_args}")
|
|
106
125
|
end
|
|
107
126
|
|
data/react_on_rails.gemspec
CHANGED
|
@@ -32,9 +32,10 @@ Gem::Specification.new do |s|
|
|
|
32
32
|
s.add_dependency "rails", ">= 3.2"
|
|
33
33
|
s.add_dependency "addressable"
|
|
34
34
|
|
|
35
|
-
s.add_development_dependency "rails", "~> 5.1.
|
|
35
|
+
s.add_development_dependency "rails", "~> 5.1.2"
|
|
36
36
|
s.add_development_dependency "bundler", "~> 1.10"
|
|
37
37
|
s.add_development_dependency "rake", "~> 10.0"
|
|
38
|
+
s.add_development_dependency "listen"
|
|
38
39
|
s.add_development_dependency "rspec"
|
|
39
40
|
s.add_development_dependency "coveralls"
|
|
40
41
|
s.add_development_dependency "generator_spec"
|
data/webpackConfigLoader.js
CHANGED
|
@@ -1,96 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Allow defaults for the config/
|
|
3
|
-
* in
|
|
2
|
+
* Allow defaults for the config/webpacker.yml. Thee values in this file MUST match values
|
|
3
|
+
* in https://github.com/rails/webpacker/blob/master/lib/install/config/webpacker.yml
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* manifest: 'manifest.json'
|
|
7
|
-
*
|
|
8
|
-
* hot_reloading_enabled_by_default: false
|
|
9
|
-
* hot_reloading_host: localhost:3500
|
|
10
|
-
*
|
|
11
|
-
* NOTE: for hot reloading, env.HOT_RELOADING value will override any config value. This env value
|
|
5
|
+
* NOTE: for HMR reloading, env.WEBPACKER_HMR value will override any config value. This env value
|
|
12
6
|
* should be set to TRUE to turn this on.
|
|
13
7
|
*/
|
|
8
|
+
|
|
14
9
|
const { join, resolve } = require('path');
|
|
10
|
+
const { env } = require('process');
|
|
15
11
|
const { safeLoad } = require('js-yaml');
|
|
16
12
|
const { readFileSync } = require('fs');
|
|
17
13
|
|
|
18
|
-
const DEFAULT_WEBPACK_PUBLIC_OUTPUT_DIR = 'webpack';
|
|
19
|
-
const DEFAULT_MANIFEST = 'manifest.json';
|
|
20
|
-
const DEFAULT_HOT_RELOADING_HOST = 'localhost:3500';
|
|
21
|
-
const HOT_RELOADING_ENABLED_BY_DEFAULT = false;
|
|
22
14
|
|
|
23
|
-
function
|
|
24
|
-
|
|
15
|
+
function removeOuterSlashes(string) {
|
|
16
|
+
return string.replace(/^\/*/, '').replace(/\/*$/, '');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function formatPublicPath(settings) {
|
|
20
|
+
if (settings.dev_server) {
|
|
21
|
+
const host = settings.dev_server.host;
|
|
22
|
+
const port = settings.dev_server.port;
|
|
23
|
+
const path = settings.public_output_path;
|
|
24
|
+
const hostWithHttp = `http://${host}:${port}`;
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
26
|
+
let formattedHost = removeOuterSlashes(hostWithHttp);
|
|
27
|
+
if (formattedHost && !/^http/i.test(formattedHost)) {
|
|
28
|
+
formattedHost = `//${formattedHost}`;
|
|
29
|
+
}
|
|
30
|
+
const formattedPath = removeOuterSlashes(path);
|
|
31
|
+
return `${formattedHost}/${formattedPath}/`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const publicOuterPathWithoutOutsideSlashes = removeOuterSlashes(settings.public_output_path);
|
|
35
|
+
return `//${publicOuterPathWithoutOutsideSlashes}/`;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* @param configPath, location where
|
|
39
|
+
* @param configPath, location where webpacker.yml will be found
|
|
40
|
+
* Return values are consistent with Webpacker's js helpers
|
|
41
|
+
* For example, you might define:
|
|
42
|
+
* const isHMR = settings.dev_server && settings.dev_server.hmr
|
|
40
43
|
* @returns {{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
* hotReloadingUrl,
|
|
46
|
-
* manifest,
|
|
47
|
-
* webpackOutputPath,
|
|
48
|
-
* webpackPublicOutputDir
|
|
49
|
-
* }}
|
|
44
|
+
settings,
|
|
45
|
+
resolvedModules,
|
|
46
|
+
output: { path, publicPath, publicPathWithHost }
|
|
47
|
+
}}
|
|
50
48
|
*/
|
|
51
49
|
const configLoader = (configPath) => {
|
|
52
|
-
const env = process.env;
|
|
53
|
-
|
|
54
50
|
// Some test environments might not have the NODE_ENV set, so we'll have fallbacks.
|
|
55
|
-
const configEnv = (
|
|
56
|
-
const ymlConfigPath = join(configPath, '
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const devBuild = env !== 'production';
|
|
60
|
-
const hotReloadingHost = configuration.hot_reloading_host || DEFAULT_HOT_RELOADING_HOST;
|
|
51
|
+
const configEnv = (env.NODE_ENV || env.RAILS_ENV || 'development');
|
|
52
|
+
const ymlConfigPath = join(configPath, 'webpacker.yml');
|
|
53
|
+
const settings = safeLoad(readFileSync(ymlConfigPath, 'utf8'))[configEnv];
|
|
61
54
|
|
|
62
55
|
// NOTE: Rails path is hard coded to `/public`
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
configuration.hot_reloading_enabled_by_default || HOT_RELOADING_ENABLED_BY_DEFAULT);
|
|
71
|
-
|
|
72
|
-
const hotReloadingUrl = hotReloadingHost.match(/^http/)
|
|
73
|
-
? hotReloadingHost
|
|
74
|
-
: `http://${hotReloadingHost}`;
|
|
75
|
-
|
|
76
|
-
const url = getLocation(hotReloadingUrl);
|
|
77
|
-
const hotReloadingPort = url.port;
|
|
78
|
-
const hotReloadingHostname = url.hostname;
|
|
79
|
-
if (hotReloadingPort === '' || hotReloadingHostname === '') {
|
|
80
|
-
const msg = 'Missing port number. Please specify the `hot_reloading_host` like `localhost:3500`';
|
|
81
|
-
throw new Error(msg);
|
|
82
|
-
}
|
|
56
|
+
const output = {
|
|
57
|
+
// Next line differs from the webpacker definition as we use the configPath to create
|
|
58
|
+
// the relative path.
|
|
59
|
+
path: resolve(configPath, '..', 'public', settings.public_output_path),
|
|
60
|
+
publicPath: `/${settings.public_output_path}/`.replace(/([^:]\/)\/+/g, '$1'),
|
|
61
|
+
publicPathWithHost: formatPublicPath(settings),
|
|
62
|
+
};
|
|
83
63
|
|
|
84
64
|
return {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
hotReloadingHost,
|
|
88
|
-
hotReloadingHostname,
|
|
89
|
-
hotReloadingPort,
|
|
90
|
-
hotReloadingUrl,
|
|
91
|
-
manifest,
|
|
92
|
-
webpackOutputPath,
|
|
93
|
-
webpackPublicOutputDir,
|
|
65
|
+
settings,
|
|
66
|
+
output,
|
|
94
67
|
};
|
|
95
68
|
};
|
|
96
69
|
|