Sha256: bb49814dab351474aa575e3c3f4364ef3283b80ae88013790edb2c5ee35b01dc

Contents?: true

Size: 840 Bytes

Versions: 6

Compression:

Stored size: 840 Bytes

Contents

require "rails/generators"

class JsRoutes::Generators::Webpacker < Rails::Generators::Base

  source_root File.expand_path(__FILE__ + "/../../../templates")

  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", "app/javascript/routes.js.erb"
    inject_into_file "config/webpack/environment.js", loader_content
    inject_into_file "app/javascript/packs/application.js", pack_content
    command = Rails.root.join("./bin/yarn add rails-erb-loader")
    run command
  end

  protected

  def pack_content
    <<-JS
import * as Routes from 'routes.js.erb';
window.Routes = Routes;
    JS
  end

  def loader_content
    <<-JS
const erb = require('./loaders/erb')
environment.loaders.append('erb', erb)
    JS
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
js-routes-2.2.5 lib/js_routes/generators/webpacker.rb
js-routes-2.2.4 lib/js_routes/generators/webpacker.rb
js-routes-2.2.3 lib/js_routes/generators/webpacker.rb
js-routes-2.2.2 lib/js_routes/generators/webpacker.rb
js-routes-2.2.1 lib/js_routes/generators/webpacker.rb
js-routes-2.2.0 lib/js_routes/generators/webpacker.rb