Skip to content

Commit

Permalink
asset_pack_path + HMR fix; Closes rails/webpacker#1171 (#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
timonbandit authored and gauravtiwari committed Jan 12, 2018
1 parent 4ab922d commit 9e2d538
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/webpacker/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ module Webpacker::Helper
#
# Example:
#
# # In development mode with hot module replacement:
# <%= asset_pack_path 'calendar.css' %> # => nil
#
# # In production mode:
# <%= asset_pack_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css"
def asset_pack_path(name, **options)
asset_path(Webpacker.manifest.lookup!(name), **options)
unless Webpacker.dev_server.running? && Webpacker.dev_server.hot_module_replacing?
asset_path(Webpacker.manifest.lookup!(name), **options)
end
end

# Computes the absolute path for a given Webpacker asset.
Expand All @@ -16,9 +22,15 @@ def asset_pack_path(name, **options)
#
# Example:
#
# # In development mode with hot module replacement:
# <%= asset_pack_url 'calendar.css' %> # => nil
#
# # In production mode:
# <%= asset_pack_url 'calendar.css' %> # => "http://example.com/packs/calendar-1016838bab065ae1e122.css"
def asset_pack_url(name, **options)
asset_url(Webpacker.manifest.lookup!(name), **options)
unless Webpacker.dev_server.running? && Webpacker.dev_server.hot_module_replacing?
asset_url(Webpacker.manifest.lookup!(name), **options)
end
end

# Creates a script tag that references the named pack file, as compiled by webpack per the entries list
Expand Down

0 comments on commit 9e2d538

Please sign in to comment.