Class: Boring::Jquery::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/boring/jquery/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_jquery_packageObject



8
9
10
11
# File 'lib/generators/boring/jquery/install/install_generator.rb', line 8

def add_jquery_package
  say "Adding JQuery packages", :green
  run "yarn add jquery"
end

#add_jquery_plugin_provider_to_webpack_environmentObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/boring/jquery/install/install_generator.rb', line 13

def add_jquery_plugin_provider_to_webpack_environment
  say "Initailizing tailwind configuration", :green
  if File.exist?("config/webpack/environment.js")
    insert_into_file "config/webpack/environment.js", <<~RUBY, after: /@rails\/webpacker.*\n/
      const webpack = require("webpack")

      environment.plugins.append("Provide", new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery'
      }))
    RUBY
  else
    say <<~WARNING, :red
      ERROR: Looks like the webpacker installation is incomplete. Could not find environment.js in config/webpack.
    WARNING
  end
end