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.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintignore +2 -0
  3. data/.gitignore +2 -2
  4. data/.rubocop.yml +5 -0
  5. data/.travis.yml +12 -1
  6. data/CHANGELOG.md +185 -6
  7. data/CONTRIBUTING.md +2 -2
  8. data/Gemfile +6 -2
  9. data/Gemfile.rails32 +74 -0
  10. data/KUDOS.md +5 -0
  11. data/README.md +200 -84
  12. data/Rakefile +11 -1
  13. data/app/helpers/react_on_rails_helper.rb +1 -1
  14. data/docs/additional-reading/asset-pipeline.md +20 -0
  15. data/docs/additional-reading/hot-reloading-rails-development.md +4 -75
  16. data/docs/additional-reading/node-server-rendering.md +2 -166
  17. data/docs/additional-reading/rails-assets-relative-paths.md +3 -1
  18. data/docs/additional-reading/rails-engine-integration.md +1 -1
  19. data/docs/additional-reading/rspec-configuration.md +7 -24
  20. data/docs/api/ruby-api-hot-reload-view-helpers.md +2 -2
  21. data/{lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt → docs/basics/configuration.md} +80 -41
  22. data/docs/basics/generator.md +0 -5
  23. data/docs/basics/installation-overview.md +6 -5
  24. data/docs/contributor-info/generator-testing.md +0 -9
  25. data/docs/tutorial.md +31 -34
  26. data/lib/generators/USAGE +0 -4
  27. data/lib/generators/react_on_rails/base_generator.rb +43 -76
  28. data/lib/generators/react_on_rails/dev_tests_generator.rb +7 -5
  29. data/lib/generators/react_on_rails/install_generator.rb +5 -10
  30. data/lib/generators/react_on_rails/react_no_redux_generator.rb +10 -9
  31. data/lib/generators/react_on_rails/react_with_redux_generator.rb +27 -17
  32. data/lib/generators/react_on_rails/templates/.eslintrc +2 -0
  33. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +4 -0
  34. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +5 -0
  35. data/lib/generators/react_on_rails/templates/base/base/{client/app → app/javascript}/bundles/HelloWorld/components/HelloWorld.jsx +1 -2
  36. data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +0 -1
  37. data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +12 -0
  38. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +41 -0
  39. data/lib/generators/react_on_rails/templates/dev_tests/.eslintrc +25 -0
  40. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +0 -1
  41. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
  42. data/lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb +2 -0
  43. data/lib/generators/react_on_rails/templates/redux/base/{client/app → app/javascript}/bundles/HelloWorld/startup/HelloWorldApp.jsx +1 -3
  44. data/lib/react_on_rails/configuration.rb +21 -16
  45. data/lib/react_on_rails/git_utils.rb +9 -3
  46. data/lib/react_on_rails/prerender_error.rb +15 -9
  47. data/lib/react_on_rails/server_rendering_pool/exec.rb +21 -8
  48. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +1 -1
  49. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +3 -1
  50. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +12 -8
  51. data/lib/react_on_rails/test_helper.rb +7 -6
  52. data/lib/react_on_rails/utils.rb +77 -16
  53. data/lib/react_on_rails/version.rb +1 -1
  54. data/lib/react_on_rails/version_checker.rb +2 -1
  55. data/lib/tasks/assets.rake +12 -4
  56. data/package.json +25 -21
  57. data/rakelib/dummy_apps.rake +9 -0
  58. data/rakelib/example_type.rb +4 -70
  59. data/rakelib/examples.rake +5 -55
  60. data/rakelib/node_package.rake +1 -0
  61. data/rakelib/release.rake +9 -1
  62. data/rakelib/run_rspec.rake +24 -5
  63. data/react_on_rails.gemspec +2 -1
  64. data/webpackConfigLoader.js +45 -72
  65. data/yarn.lock +638 -252
  66. metadata +36 -26
  67. data/lib/generators/react_on_rails/node_generator.rb +0 -24
  68. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +0 -2
  69. data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb.tt +0 -15
  70. data/lib/generators/react_on_rails/templates/base/base/client/.babelrc +0 -3
  71. data/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md +0 -9
  72. data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +0 -36
  73. data/lib/generators/react_on_rails/templates/base/base/client/webpack.config.js +0 -77
  74. data/lib/generators/react_on_rails/templates/base/base/config/webpacker_lite.yml +0 -27
  75. data/lib/generators/react_on_rails/templates/base/base/package.json.tt +0 -8
  76. data/lib/generators/react_on_rails/templates/node/base/client/node/package.json +0 -10
  77. data/lib/generators/react_on_rails/templates/node/base/client/node/server.js +0 -105
  78. /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
  79. /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
  80. /data/lib/generators/react_on_rails/templates/redux/base/{client/app → app/javascript}/bundles/HelloWorld/components/HelloWorld.jsx +0 -0
  81. /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
  82. /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
  83. /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
  84. /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
@@ -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 prepare clean clobber npm_install build_webpack_bundles].each do |task_type|
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 = []
@@ -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.clean_task_name do
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
- end
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
- multitask gen_all: ExampleType.all.map(&:gen_task_name)
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 "Prepares all example apps. Run `rake -D examples` to see all available options"
99
- multitask examples: ["examples:prepare_all"]
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
 
@@ -5,6 +5,7 @@ include ReactOnRails::TaskHelpers
5
5
 
6
6
  namespace :node_package do
7
7
  task :build do
8
+ puts "Building Node Package and running 'yarn link'"
8
9
  sh "yarn run build && yarn link"
9
10
  end
10
11
  end
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
- sh_in_dir(gem_root, "gem release") unless is_dry_run
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
@@ -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.prepare_task_name do
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:prepare_all" do
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 = <<~DESC
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, '')} COVERAGE=true TEST_ENV_COMMAND_NAME="#{command_name}")
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
 
@@ -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.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"
@@ -1,96 +1,69 @@
1
1
  /**
2
- * Allow defaults for the config/webpacker_lite.yml. Thee values in this file MUST match values
3
- * in README for https://github.com/shakacode/webpacker_lite
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
- * webpack_public_output_dir: 'webpack'
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 getLocation(href) {
24
- const match = href.match(/^(https?:)\/\/(([^:/?#]*)(?::([0-9]+))?)([/]?[^?#]*)(\?[^#]*|)(#.*|)$/);
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
- return match && {
27
- href,
28
- protocol: match[1],
29
- host: match[2],
30
- hostname: match[3],
31
- port: match[4],
32
- pathname: match[5],
33
- search: match[6],
34
- hash: match[7],
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 webpacker_lite.yml will be found
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
- * devBuild,
42
- * hotReloadingEnabled,
43
- * hotReloadingHost,
44
- * hotReloadingPort,
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 = (process.env.NODE_ENV || process.env.RAILS_ENV || 'development');
56
- const ymlConfigPath = join(configPath, 'webpacker_lite.yml');
57
- const configuration = safeLoad(readFileSync(ymlConfigPath, 'utf8'))[configEnv];
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 webpackPublicOutputDir = configuration.webpack_public_output_dir ||
64
- DEFAULT_WEBPACK_PUBLIC_OUTPUT_DIR;
65
- const webpackOutputPath = resolve(configPath, '..', 'public', webpackPublicOutputDir);
66
-
67
- const manifest = configuration.manifest || DEFAULT_MANIFEST;
68
-
69
- const hotReloadingEnabled = (env.HOT_RELOADING === 'TRUE' || env.HOT_RELOADING === 'YES' ||
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
- devBuild,
86
- hotReloadingEnabled,
87
- hotReloadingHost,
88
- hotReloadingHostname,
89
- hotReloadingPort,
90
- hotReloadingUrl,
91
- manifest,
92
- webpackOutputPath,
93
- webpackPublicOutputDir,
65
+ settings,
66
+ output,
94
67
  };
95
68
  };
96
69