Class: ReactWebpackRails::Install::HotReloadGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
MergeHelpers
Defined in:
lib/generators/react_webpack_rails/install/hot_reload_generator.rb

Instance Method Summary collapse

Instance Method Details

#hot_dev_configObject



20
21
22
# File 'lib/generators/react_webpack_rails/install/hot_reload_generator.rb', line 20

def hot_dev_config
  copy_file 'webpack/hot-dev.config.js', 'webpack/hot-dev.config.js'
end

#indexObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/react_webpack_rails/install/hot_reload_generator.rb', line 40

def index
  append_to_file 'app/react/index.js' do <<-'JS'.strip_heredoc

    if (module.hot) {
      module.hot.accept();
      RWR.reloadNodes();
    }
    JS
  end
end

#packageObject



15
16
17
18
# File 'lib/generators/react_webpack_rails/install/hot_reload_generator.rb', line 15

def package
  merge_options = options.tmp_package ? { package_file: 'tmp/package.json', force: true } : {}
  merge_into_package 'packages/hot-reload.json', merge_options
end

#partialObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/react_webpack_rails/install/hot_reload_generator.rb', line 24

def partial
  copy_file 'partial/_react_hot_assets.html.erb', 'app/views/layouts/_react_hot_assets.html.erb'
  settings = template_language_settings("render 'layouts/react_hot_assets'")

  missing_layout_info = <<-NO_MANIFEST.strip_heredoc
    Application Layout not found.

    Application Layout (normally app/views/layouts/appliaction.html.erb) could not be found.
    Please add in you main layout: "render 'layouts/react_hot_assets'"
  NO_MANIFEST

  return say_status(:not_found, missing_layout_info, :red) if settings == :no_application_layout

  inject_into_file settings[:layout_file], settings[:parsed_command], after: "#{settings[:body_tag]}\n"
end