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

参考:

Sprockets の仕組み – Qiita

アセットパイプラインのコードリーディング | freedom-man.com

sprockets/how_sprockets_works.md at master · rails/sprockets – GitHub

sprockets/extending_sprockets.md at master · rails/sprockets – GitHub

How the F does Sprockets Load an Asset? | Schneems

Demystifying Sprockets | byroot.github.io

Sprockets.config

参考:

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

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::Base#[]

参考:

sprockets/base.rb at v3.7.2 · rails/sprockets – 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

参考:

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

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

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

file_digest / stat_digest

参考:

file_digest – sprockets/path_digest_utils.rb at v3.7.2 · rails/sprockets – GitHub

stat_digest – sprockets/path_digest_utils.rb at v3.7.2 · rails/sprockets – GitHub

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

resolve_with_compat – sprockets/legacy.rb at v3.7.2 · rails/sprockets – GitHub

build_asset_uri

参考:

build_asset_uri – sprockets/uri_utils.rb at v3.7.2 · rails/sprockets – GitHub

Sprockets::Loader

参考:

sprockets/loader.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

Sprockets::UnloadedAsset

参考:

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

digest_class

参考:

Reducing rails asset pipeline’s 64 bytes of digest size | Linux Tips

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

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

detect_digest_class – sprockets/digest_utils.rb at v3.7.2 · rails/sprockets – GitHub

Rails asset pipeline and digest values – Stack Overflow

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

enhance – 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

Sprockets::Rails::Task#manifeset

参考:

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

Rake::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

Sprockets::Manifest#compile

参考:

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

Sprockets::Manifest#exporters_for_asset

参考:

exporters_for_asset – sprockets/manifest.rb at v4.0.0.beta9 · rails/sprockets – GitHub

compile – sprockets/manifest.rb at v4.0.0.beta9 · 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

Sprockets::ERBProcessor

参考:

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

register_transformer_suffix

参考:

Method: Sprockets::Transformers#register_transformer_suffix — Documentation for rails/sprockets | RubyDoc.info

ERBProcessor – sprockets/sprockets.rb at v4.0.0.beta9 · rails/sprockets – GitHub

added text/eco to register_transformer_suffix for ERBProcessor by marcreynolds · Pull Request #491 · rails/sprockets – GitHub

asset_path

参考:

rails/asset_url_helper.rb at v5.2.2 · rails/rails – GitHub

image_path

参考:

rails/asset_url_helper.rb at v5.2.2 · rails/rails – GitHub

compute_asset_path

参考:

sprockets-rails/helper.rb at v3.2.1 · rails/sprockets-rails – 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

指定したアセットをコンパイルする

指定した単一のアセットのみをコンパイルする。

Sprockets::Manifest.new(
  Rails.application.assets.cached,
  File.join(Rails.public_path, Rails.application.config.assets.prefix),
  Rails.application.config.assets.manifest
).compile("path/to/asset.css")

Sprockets::Context

参考:

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

Sprockets::Processing

  • register_pipeline
  • register_bundle_processor
  • register_preprocessor
  • register_postprocessor
  • register_bundle_metadata_reducer

参考:

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

Module: Sprockets::Processing — Documentation for sprockets | RubyDoc.info

Polymer on Rails, tooling the asset pipeline for performance | Cooking Healthy Code

register_bundle_metadata_reducer

中間生成データを一つのデータにまとめる (あるいは一つのファイルに出力する) ためのリデューサーを登録する。

参考:

register_bundle_metadata_reducer – sprockets/processing.rb at v3.7.2 · rails/sprockets – GitHub

Sprockets::Compressing

  • register_compressor
  • js_compressor=
  • css_compressor=

参考:

register_compressor – sprockets/compressing.rb at v3.7.2 · rails/sprockets – GitHub

Module: Sprockets::Compressing — Documentation for sprockets | RubyDoc.info

Sprockets::Transformers

  • register_transformer

参考:

register_transformer – sprockets/transformers.rb at v3.7.2 · rails/sprockets – GitHub

Module: Sprockets::Transformers — Documentation for sprockets | RubyDoc.info

Sprockets::Exporting

  • register_exporter

参考:

sprockets/exporting.rb at v4.0.0.beta9 · rails/sprockets – GitHub

register_exporter

参考:

register_exporter – sprockets/exporting.rb at v4.0.0.beta9 · rails/sprockets – GitHub

hash_reassoc

複製したハッシュに要素を追加してフリーズして返す。フリーズされたconfig に設定を追加するために用いる。

参考:

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

concat_javascript_sources

参考:

concat_javascript_sources – sprockets/utils.rb at v3.7.2 · rails/sprockets – GitHub

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

Sprockets Semicolon insertion causes sourcemap to be off by (n) number of lines · Issue #388 · rails/sprockets – GitHub

[close #388] Do not add newline when appending Semi-colons · rails/sprockets@1d28403 – GitHub

SasscProcessor

参考:

sprockets/sassc_processor.rb at v4.0.0.beta10 · rails/sprockets – GitHub

記事をシェアする:
タグ:

コメントを残す

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

Protected by reCAPTCHA