From c46d751b12cc7e24661bc76ad5ebebd0e08c7dda Mon Sep 17 00:00:00 2001 From: Dima Lunkin Date: Fri, 12 Jan 2018 15:48:19 +0300 Subject: [PATCH] asset_pack_path + HMR fix; Closes rails/webpacker#1171 (#1172) --- lib/webpacker/helper.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/webpacker/helper.rb b/lib/webpacker/helper.rb index 173e2af1b..34849dc8f 100644 --- a/lib/webpacker/helper.rb +++ b/lib/webpacker/helper.rb @@ -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. @@ -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