From 8c947eb6e95f50ae88e19c0f036bd4a3d3b2dece Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 9 Dec 2016 12:19:43 -0800 Subject: Basic --webpack delegation to new webpacker gem (#27288) --- railties/lib/rails/generators/app_base.rb | 15 +++++++++++++++ railties/lib/rails/generators/rails/app/app_generator.rb | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index aba68d6db2..2f7339e7f5 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -33,6 +33,9 @@ module Rails class_option :javascript, type: :string, aliases: "-j", desc: "Preconfigure for selected JavaScript library" + class_option :webpack, type: :boolean, default: false, + desc: "Preconfigure for app-like JavaScript with Webpack" + class_option :skip_yarn, type: :boolean, default: false, desc: "Don't use Yarn for managing JavaScript dependencies" @@ -128,6 +131,7 @@ module Rails database_gemfile_entry, webserver_gemfile_entry, assets_gemfile_entry, + webpacker_gemfile_entry, javascript_gemfile_entry, jbuilder_gemfile_entry, psych_gemfile_entry, @@ -315,6 +319,13 @@ module Rails gems end + def webpacker_gemfile_entry + if options[:webpack] + comment = "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker" + GemfileEntry.new "webpacker", "~> 0.1", comment + end + end + def jbuilder_gemfile_entry comment = "Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder" GemfileEntry.new "jbuilder", "~> 2.5", comment, {}, options[:api] @@ -414,6 +425,10 @@ module Rails bundle_command("install") if bundle_install? end + def run_webpack + rails_command "webpacker:install" + end + def generate_spring_binstubs if bundle_install? && spring_install? bundle_command("exec spring binstub --all") diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index a8586d56dd..19d3ba2f0f 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -357,7 +357,7 @@ module Rails end public_task :apply_rails_template, :run_bundle - public_task :generate_spring_binstubs + public_task :run_webpack, :generate_spring_binstubs def run_after_bundle_callbacks @after_bundle_callbacks.each(&:call) -- cgit v1.2.3