Class: WebpackAssets::Init

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/webpack_assets/generators/init.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



8
9
10
# File 'lib/webpack_assets/generators/init.rb', line 8

def self.source_root
  @source_root ||= File.join(File.dirname(__FILE__), 'templates')
end

Instance Method Details

#add_configObject



33
34
35
36
# File 'lib/webpack_assets/generators/init.rb', line 33

def add_config
  application "config.webpack_build_path = 'app/assets/javascripts/bundle.js'"
  application "# path or glob to webpack built assets"
end

#create_package_fileObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/webpack_assets/generators/init.rb', line 22

def create_package_file
  destination = 'package.json'
  if File.exist?(destination)
    puts "Skipping #{destination} because it already exists"
    puts "** make sure 'package.json' includes 'webpack' and 'jsx-loader' dependencies"
  else
    template 'package.json', destination
    system "npm install"
  end
end

#create_webpack_fileObject



12
13
14
15
16
17
18
19
20
# File 'lib/webpack_assets/generators/init.rb', line 12

def create_webpack_file
  destination = 'webpack.config.js'
  if File.exist?(destination)
    puts "Skipping #{destination} because it already exists"
  else
    copy_file 'webpack.config.js', destination
    puts "** update the entry point in 'webpack.config.js' "
  end
end