diff --git a/lib/webpacker/helper.rb b/lib/webpacker/helper.rb index 34849dc8f..54e106dc2 100644 --- a/lib/webpacker/helper.rb +++ b/lib/webpacker/helper.rb @@ -11,7 +11,7 @@ module Webpacker::Helper # # In production mode: # <%= asset_pack_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css" def asset_pack_path(name, **options) - unless Webpacker.dev_server.running? && Webpacker.dev_server.hot_module_replacing? + unless stylesheet?(name) && Webpacker.dev_server.running? && Webpacker.dev_server.hot_module_replacing? asset_path(Webpacker.manifest.lookup!(name), **options) end end @@ -68,6 +68,10 @@ def stylesheet_pack_tag(*names, **options) end private + def stylesheet?(name) + File.extname(name) == ".css" + end + def sources_from_pack_manifest(names, type:) names.map { |name| Webpacker.manifest.lookup!(pack_name_with_extension(name, type: type)) } end diff --git a/test/helper_test.rb b/test/helper_test.rb index 28f7f097d..85d7a789d 100644 --- a/test/helper_test.rb +++ b/test/helper_test.rb @@ -17,6 +17,13 @@ def base_url def test_asset_pack_path assert_equal "/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_path("bootstrap.js") assert_equal "/packs/bootstrap-c38deda30895059837cf.css", asset_pack_path("bootstrap.css") + + Webpacker.dev_server.stub :running?, true do + Webpacker.dev_server.stub :hot_module_replacing?, true do + assert_nil asset_pack_path("bootstrap.css") + assert_equal "/packs/application-k344a6d59eef8632c9d1.png", asset_pack_path("application.png") + end + end end def test_asset_pack_url diff --git a/test/test_app/public/packs/manifest.json b/test/test_app/public/packs/manifest.json index f7b77dd63..bcce14cec 100644 --- a/test/test_app/public/packs/manifest.json +++ b/test/test_app/public/packs/manifest.json @@ -2,5 +2,6 @@ "bootstrap.css": "/packs/bootstrap-c38deda30895059837cf.css", "application.css": "/packs/application-dd6b1cd38bfa093df600.css", "bootstrap.js": "/packs/bootstrap-300631c4f0e0f9c865bc.js", - "application.js": "/packs/application-k344a6d59eef8632c9d1.js" + "application.js": "/packs/application-k344a6d59eef8632c9d1.js", + "application.png": "/packs/application-k344a6d59eef8632c9d1.png" }