class Webpacker::Manifest
Public Class Methods
exist?()
click to toggle source
Helper method to determine if the manifest file exists. Maybe Webpack needs to run? **Used by React on Rails.**
# File lib/webpacker/manifest.rb, line 35 def exist? path_object = Webpacker::Configuration.manifest_path path_object.exist? end
file_path()
click to toggle source
# File lib/webpacker/manifest.rb, line 12 def file_path Webpacker::Configuration.manifest_path end
lookup(name)
click to toggle source
Throws an error if the file is not found. If Configuration.compile? then compilation is invoked the file is missing. React on Rails users will need to set Configuration.compile? to false as compilation is configured in the package.json for React on Rails.
# File lib/webpacker/manifest.rb, line 20 def lookup(name) if Webpacker::Configuration.compile? compile_and_find!(name) else find!(name) end end
lookup_no_throw(name)
click to toggle source
Find the real file name from the manifest key. Don't throw an error if the file is simply missing from the manifest. Return nil in that case. If no manifest file exists, then throw an error. **Used by React on Rails.**
# File lib/webpacker/manifest.rb, line 44 def lookup_no_throw(name) instance.confirm_manifest_exists load_instance unless instance raise Webpacker::FileLoader::FileLoaderError.new("Webpacker::Manifest.load must be called first") end instance.data[name.to_s] end
lookup_path(name)
click to toggle source
Why does this method exist? Testing? It's not in the README
# File lib/webpacker/manifest.rb, line 29 def lookup_path(name) Rails.root.join(File.join(Webpacker::Configuration.output_path, lookup(name))) end
Private Class Methods
compile_and_find!(name)
click to toggle source
# File lib/webpacker/manifest.rb, line 85 def compile_and_find!(name) Webpacker.compile find!(name) end
find!(name)
click to toggle source
# File lib/webpacker/manifest.rb, line 55 def find!(name) unless instance raise Webpacker::FileLoader::FileLoaderError.new("Webpacker::Manifest.load must be called first") end instance.data[name.to_s] || missing_file_from_manifest_error(name) end
missing_file_from_manifest_error(bundle_name)
click to toggle source
# File lib/webpacker/manifest.rb, line 62 def missing_file_from_manifest_error(bundle_name) msg = <<-MSG Webpacker can't find #{bundle_name} in your manifest at #{file_path}. Possible causes: 1. You are hot reloading. 2. You want to set Configuration.compile to true for your environment. 3. Webpack has not re-run to reflect updates. 4. You have misconfigured Webpacker's config/webpacker.yml file. 5. Your Webpack configuration is not creating a manifest. MSG raise(Webpacker::FileLoader::NotFoundError.new(msg)) end
missing_manifest_file_error(path_object)
click to toggle source
# File lib/webpacker/manifest.rb, line 74 def missing_manifest_file_error(path_object) msg = <<-MSG Webpacker can't find the manifest file: #{path_object} Possible causes: 1. You have not invoked webpack. 2. You have misconfigured Webpacker's config/webpacker_.yml file. 3. Your Webpack configuration is not creating a manifest. MSG raise(Webpacker::FileLoader::NotFoundError.new(msg)) end
Public Instance Methods
confirm_manifest_exists()
click to toggle source
# File lib/webpacker/manifest.rb, line 91 def confirm_manifest_exists raise missing_manifest_file_error(@path) unless File.exist?(@path) end
Private Instance Methods
load_data()
click to toggle source
Calls superclass method
Webpacker::FileLoader#load_data
# File lib/webpacker/manifest.rb, line 97 def load_data return super unless File.exist?(@path) JSON.parse(File.read(@path)) end