アセットパイプラインの仕組み (Sprockets)

Sprockets::Railtie

参考:

Sprockets::Railtie – sprockets-rails/railtie.rb at v3.2.1 · rails/sprockets-rails – GitHub

Sprockets::Environment

参考:

Class: Sprockets::Environment — Documentation for sprockets | RubyDoc.info

sprockets/environment.rb at v3.7.2 · rails/sprockets – GitHub

assets_environment – sprockets-rails/railtie.rb at v3.2.1 · rails/sprockets-rails – GitHub

Sprockets::Asset

参考:

Class: Sprockets::Asset — Documentation for sprockets | RubyDoc.info

sprockets/asset.rb at v3.7.2 · rails/sprockets – GitHub

digest_path

参考:

digest_path – sprockets/asset.rb at v3.7.2 · rails/sprockets – GitHub

digest

参考:

etag – sprockets/asset.rb at v3.7.2 · rails/sprockets – GitHub

hexdigest – sprockets/asset.rb at v3.7.2 · rails/sprockets – GitHub

pack_hexdigest – sprockets/digest_utils.rb at v3.7.2 · rails/sprockets

find_asset

参考:

find_asset – sprockets/base.rb at v3.7.2 · rails/sprockets – GitHub

resolve

参考:

resolve – sprockets/resolve.rb at v3.7.2 · rails/sprockets – GitHub

load

参考:

load – sprockets/loader.rb at v3.7.2 · rails/sprockets – GitHub

load_from_unloaded – sprockets/loader.rb at v3.7.2 · rails/sprockets – GitHub

metadata[:digest]

参考:

metadata[:digest] – sprockets/loader.rb at v3.7.2 · rails/sprockets – GitHub

metadata[:digest] – sprockets/loader.rb at v3.7.2 · rails/sprockets – GitHub

digest_class

参考:

digest_class – sprockets/sprockets.rb at v3.7.2 · rails/sprockets – GitHub

digest_class – sprockets/configuration.rb at v3.7.2 · rails/sprockets – GitHub

assets:precompile

参考:

assets:precompile – sprockets-rails/task.rb at v3.2.1 · rails/sprockets-rails – GitHub

enhance_assets_precompile

参考:

enhance_assets_precompile – webpacker/compile.rake at v4.0.0.pre.3 · rails/webpacker – GitHub

enhance_assets_precompile – webpacker/compile.rake at v4.0.0.pre.3 · rails/webpacker – GitHub

yarn:install

参考:

yarn:install – rails/yarn.rake at v5.2.2 · rails/rails – GitHub

yarn:install – rails/yarn.rake at v5.2.2 · rails/rails – GitHub

Sprockets::Rails::Task

参考:

sprockets-rails/task.rb at v3.2.1 · rails/sprockets-rails – GitHub

Sprockets::Rails::Task – sprockets-rails/railtie.rb at v3.2.1 · rails/sprockets-rails – GitHub

Raks::SprocketsTask

参考:

SprocketsTask – sprockets/sprocketstask.rb at v3.7.2 · rails/sprockets – GitHub

cached – sprockets/sprocketstask.rb at v3.7.2 · rails/sprockets – GitHub

with_logger – sprockets/sprocketstask.rb at v3.7.2 · rails/sprockets – GitHub

Sprockets::Manifest

参考:

sprockets/manifest.rb at v3.7.2 · rails/sprockets – GitHub

compile – sprockets/manifest.rb at v3.7.2 · rails/sprockets – GitHub

ManifestUtils

参考:

find_directory_manifest – sprockets/manifest_utils.rb at v3.7.2 · rails/sprockets – GitHub

generate_manifest_path – sprockets/manifest_utils.rb at v3.7.2 · rails/sprockets – GitHub

アセットをコンパイルするタスクを自前で用意する

desc "Compile assets"
task compile_assets: :environment do
  app    = Rails.application
  config = app.config
  index  = app.assets.cached

  output = File.join(
    config.paths["public"].first,
    config.assets.prefix
  )

  manifest_path = File.expand_path(
    "tmp/tmp.sprockets-manifest-#{SecureRandom.hex(16)}.json",
    Rails.root
  )

  puts "cached_env: #{index}"
  puts "output_dir: #{output}"
  puts "manifest_path: #{manifest_path}"

  manifest = Sprockets::Manifest.new(
    index,
    output,
    manifest_path
  )

  logger       = Logger.new($stderr)
  logger.level = Logger::INFO
  env          = manifest.environment
  env.logger   = logger

  assets = app.config.assets.precompile

  manifest.compile(assets)
end

アセットをコンパイルする

$ rails compile_assets
Tagged:

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です