class Webpacker::Manifest
Singleton registry for accessing the packs path using a generated manifest. This allows javascript_pack_tag, stylesheet_pack_tag, asset_pack_path to take a reference to, say, “calendar.js” or “calendar.css” and turn it into “/packs/calendar.js” or “/packs/calendar.css” in development.
In production mode, it returns compiles files, like “/packs/calendar-1016838bab065ae1e314.js” and “/packs/calendar-1016838bab065ae1e314.css”, for long-term caching.
When the configuration is set to on-demand compilation, with the `compile: true` option in the webpacker.yml file, any lookups will be preceeded by a compilation if one is needed.
Public Class Methods
new(webpacker)
click to toggle source
# File lib/webpacker-for-component/manifest.rb, line 17 def initialize(webpacker) @webpacker = webpacker end
Public Instance Methods
lookup(name)
click to toggle source
# File lib/webpacker-for-component/manifest.rb, line 25 def lookup(name) compile if compiling? find name end
refresh()
click to toggle source
# File lib/webpacker-for-component/manifest.rb, line 21 def refresh @data = load end
Private Instance Methods
compile()
click to toggle source
# File lib/webpacker-for-component/manifest.rb, line 35 def compile Webpacker.logger.tagged("Webpacker") { compiler.compile } end
compiling?()
click to toggle source
# File lib/webpacker-for-component/manifest.rb, line 31 def compiling? config.compile? && !dev_server.running? end
data()
click to toggle source
# File lib/webpacker-for-component/manifest.rb, line 60 def data if config.cache_manifest? @data ||= load else refresh end end
find(name)
click to toggle source
# File lib/webpacker-for-component/manifest.rb, line 39 def find(name) data[name.to_s] || handle_missing_entry(name) end
handle_missing_entry(name)
click to toggle source
# File lib/webpacker-for-component/manifest.rb, line 43 def handle_missing_entry(name) raise Webpacker::Manifest::MissingEntryError, missing_file_from_manifest_error(name) end
load()
click to toggle source
# File lib/webpacker-for-component/manifest.rb, line 68 def load if config.public_manifest_path.exist? react_json=JSON.parse Rails.root.join("public/packs/react/manifest.json").read vue_json=JSON.parse Rails.root.join("public/packs/vue/manifest.json").read angular_json=JSON.parse config.public_manifest_path.read angular_react=react_json.merge(angular_json) angular_react.merge(vue_json) else {} end end
missing_file_from_manifest_error(bundle_name)
click to toggle source
# File lib/webpacker-for-component/manifest.rb, line 47 def missing_file_from_manifest_error(bundle_name) msg = <<-MSG Webpacker can't find #{bundle_name} in #{config.public_manifest_path}. Possible causes: 1. You want to set webpacker.yml value of compile to true for your environment unless you are using the `webpack -w` or the webpack-dev-server. 2. Webpack has not yet re-run to reflect updates. 3. You have misconfigured Webpacker's config/webpacker.yml file. 4. Your Webpack configuration is not creating a manifest. Your manifest contains: #{JSON.pretty_generate(@data)} MSG end