Skip to content

Commit

Permalink
configuration.rb, manifest.rb to handle no compile
Browse files Browse the repository at this point in the history
This fix addresses the cases where compile is disabled:

1. If React on Rails depends on Webpacker, but the React on Rails
installer has not yet generated a webpacker.yml file or a React on Rails
installation is not using Webpacker, then the gem loading of Webpacker
will crash due to the missing config file.

2. If React on Rails has its own helper to compile assets for tests,
then the manifest might need to get reloaded after Webpacker statically
loads.
  • Loading branch information
justin808 committed Aug 14, 2017
1 parent 700c92b commit 7abcc21
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
15 changes: 11 additions & 4 deletions lib/webpacker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,22 @@ def fetch(key)
end

def data
if env.development?
refresh
else
if env.production?
@data ||= load
else
refresh
end
end

def load
YAML.load(config_path.read)[env].deep_symbolize_keys
if config_path.exist? &&
(@parsed_mtime.nil? ||
((config_mtime = File.mtime(config.public_manifest_path)) > @parsed_mtime))
@parsed_mtime = config_mtime
YAML.load(config_path.read)[env].deep_symbolize_keys
else
{}
end
end

def defaults
Expand Down
27 changes: 22 additions & 5 deletions lib/webpacker/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,36 @@ def find(name)

def handle_missing_entry(name)
raise Webpacker::Manifest::MissingEntryError,
"Can't find #{name} in #{config.public_manifest_path}. Is webpack still compiling?"
"Can't find #{name} in #{config.public_manifest_path}. Manifest contains: #{@data}"
end

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 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.
Your manifest contains:
#{@data.to_json}
MSG
raise(Webpacker::FileLoader::NotFoundError.new(msg))
end

def data
if env.development?
refresh
else
if env.production?
@data ||= load
else
refresh
end
end

def load
if config.public_manifest_path.exist?
if config.public_manifest_path.exist? &&
(@parsed_mtime.nil? ||
((manifest_mtime = File.mtime(config.public_manifest_path)) > @parsed_mtime))
@parsed_mtime = manifest_mtime
JSON.parse config.public_manifest_path.read
else
{}
Expand Down

0 comments on commit 7abcc21

Please sign in to comment.