Sha256: 058312a22d2ea8981c29c472029755bd4c752877ccee8019a43bcaab458c1afb

Contents?: true

Size: 1.16 KB

Versions: 9

Compression:

Stored size: 1.16 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

if Webpacker.config.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

9 entries across 9 versions & 1 rubygems

Version Path
shakapacker-6.5.5 lib/tasks/webpacker/compile.rake
shakapacker-6.5.4 lib/tasks/webpacker/compile.rake
shakapacker-6.5.3 lib/tasks/webpacker/compile.rake
shakapacker-6.5.2 lib/tasks/webpacker/compile.rake
shakapacker-6.5.1 lib/tasks/webpacker/compile.rake
shakapacker-6.5.0 lib/tasks/webpacker/compile.rake
shakapacker-6.4.1 lib/tasks/webpacker/compile.rake
shakapacker-6.3.0 lib/tasks/webpacker/compile.rake
shakapacker-6.3.0.pre.rc.1 lib/tasks/webpacker/compile.rake