Class: Webpacked::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/webpacked/manifest.rb

Overview

Webpack manifest loading, caching and entry point retrieval

Defined Under Namespace

Classes: EntryMissingError, LoadError, UnknownAssetKindError

Constant Summary collapse

ASSET_KINDS =
[:js, :css]

Class Method Summary collapse

Class Method Details

.asset_paths(entry, kind = nil) ⇒ Object

Load manifest from file and cache it if Rails.configuration.webpacked.dev_server set to false. Return entry point asset path for :js or :css kind or both if kind skipped



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/webpacked/manifest.rb', line 27

def asset_paths(entry, kind = nil)
  return unless Rails.configuration.webpacked.enabled

  validate_asset_kind(kind)
  if Rails.configuration.webpacked.dev_server
    @manifest = load_manifest!
  else
    @manifest ||= load_manifest!
  end
  validate_entry(entry)

  return @manifest[entry] unless kind
  return @manifest[entry][kind] if @manifest[entry]
end

.load_manifest!Object

Force to load manifest from file

Raises:



43
44
45
46
47
48
49
50
51
# File 'lib/webpacked/manifest.rb', line 43

def load_manifest!
  manifest_path = Rails.configuration.webpacked.manifest_path
  manifest_path = Rails.root.join(manifest_path)
  raise LoadError, "File #{manifest_path} not found" unless File.exist?(manifest_path)

  manifest = JSON.parse(File.read manifest_path).with_indifferent_access
  clean_asset_paths(manifest)
  manifest
end