Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
43 lines (37 sloc)
1.23 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$stdout.sync = true | |
def yarn_install_available? | |
rails_major = Rails::VERSION::MAJOR | |
rails_minor = Rails::VERSION::MINOR | |
rails_major > 5 || (rails_major == 5 && rails_minor >= 1) | |
end | |
def enhance_assets_precompile | |
# yarn:install was added in Rails 5.1 | |
deps = yarn_install_available? ? [] : ["webpacker:yarn_install"] | |
Rake::Task["assets:precompile"].enhance(deps) do | |
Rake::Task["webpacker:compile"].invoke | |
end | |
end | |
namespace :webpacker do | |
desc "Compile JavaScript packs using webpack for production with digests" | |
task compile: ["webpacker:verify_install", :environment] do | |
Webpacker.with_node_env(ENV.fetch("NODE_ENV", "production")) do | |
Webpacker.ensure_log_goes_to_stdout do | |
if Webpacker.compile | |
# Successful compilation! | |
else | |
# Failed compilation | |
exit! | |
end | |
end | |
end | |
end | |
end | |
# Compile packs after we've compiled all other assets during precompilation | |
skip_webpacker_precompile = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"]) | |
unless skip_webpacker_precompile | |
if Rake::Task.task_defined?("assets:precompile") | |
enhance_assets_precompile | |
else | |
Rake::Task.define_task("assets:precompile" => ["webpacker:yarn_install", "webpacker:compile"]) | |
end | |
end |