Class: ActiveAdmin::Generators::WebpackerGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/active_admin/webpacker/webpacker_generator.rb

Instance Method Summary collapse

Instance Method Details

#install_assetsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/generators/active_admin/webpacker/webpacker_generator.rb', line 8

def install_assets
  template "active_admin.js", "app/javascript/packs/active_admin.js"
  template "active_admin.scss", "app/javascript/stylesheets/active_admin.scss"
  template "print.scss", "app/javascript/packs/active_admin/print.scss"

  copy_file "#{__dir__}/plugins/jquery.js", Rails.root.join("config/webpack/plugins/jquery.js").to_s

  insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
                   "const jquery = require('./plugins/jquery')\n",
                   after: /require\(('|")@rails\/webpacker\1\);?\n/

  insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
                   "environment.plugins.prepend('jquery', jquery)\n",
                   before: "module.exports"

  run "yarn add @activeadmin/activeadmin"
end