class JsRoutes::Generators::Webpacker

Public Instance Methods

create_webpack() click to toggle source
# File lib/js_routes/generators/webpacker.rb, line 6
def create_webpack
  copy_file "initializer.rb", "config/initializers/js_routes.rb"
  copy_file "erb.js", "config/webpack/loaders/erb.js"
  copy_file "routes.js.erb", "#{JsRoutes::Utils.shakapacker.config.source_path}/routes.js.erb"
  inject_into_file "config/webpack/environment.js", loader_content
  if path = application_js_path
    inject_into_file path, pack_content
  end
  command = Rails.root.join("./bin/yarn add rails-erb-loader")
  run command
end

Protected Instance Methods

loader_content() click to toggle source
# File lib/js_routes/generators/webpacker.rb, line 27
  def loader_content
    <<-JS
const erb = require('./loaders/erb')
environment.loaders.append('erb', erb)
    JS
  end
pack_content() click to toggle source
# File lib/js_routes/generators/webpacker.rb, line 20
  def pack_content
    <<-JS
import * as Routes from 'routes.js.erb';
alert(Routes.root_path())
    JS
  end