Sha256: 32a48ee94d29f92b79b3972915eb9be06037f58650cb3d8548b9177a7bead999

Contents?: true

Size: 1.31 KB

Versions: 28

Compression:

Stored size: 1.31 KB

Contents

$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 |task|
    prefix = task.name.split(/#|assets:precompile/).first

    Rake::Task["#{prefix}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

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
shakapacker-6.2.1 lib/tasks/webpacker/compile.rake
shakapacker-6.2.0 lib/tasks/webpacker/compile.rake
shakapacker-6.1.1 lib/tasks/webpacker/compile.rake
shakapacker-6.1.0 lib/tasks/webpacker/compile.rake
shakapacker-6.1.0.beta.0 lib/tasks/webpacker/compile.rake
shakapacker-6.0.2 lib/tasks/webpacker/compile.rake
shakapacker-6.0.1 lib/tasks/webpacker/compile.rake
shakapacker-6.0.0 lib/tasks/webpacker/compile.rake
shakapacker-6.0.0.rc.14 lib/tasks/webpacker/compile.rake
shakapacker-6.0.0.rc.13 lib/tasks/webpacker/compile.rake
shakapacker-6.0.0.rc.12 lib/tasks/webpacker/compile.rake
shakapacker-6.0.0.rc.6 lib/tasks/webpacker/compile.rake
webpacker-6.0.0.rc.6 lib/tasks/webpacker/compile.rake
webpacker-6.0.0.rc.5 lib/tasks/webpacker/compile.rake
webpacker-6.0.0.rc.4 lib/tasks/webpacker/compile.rake
webpacker-6.0.0.rc.3 lib/tasks/webpacker/compile.rake
webpacker-6.0.0.rc.2 lib/tasks/webpacker/compile.rake
webpacker-6.0.0.rc.1 lib/tasks/webpacker/compile.rake
webpacker-6.0.0.beta.7 lib/tasks/webpacker/compile.rake
webpacker-6.0.0.beta.6 lib/tasks/webpacker/compile.rake