From a6a8b45dc0e2bca67cac1eac83fb14afaf22420d Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Sun, 28 Jan 2018 19:00:03 +0000 Subject: [PATCH 1/2] Fix asset helper for non-css assets in hmr mode --- lib/webpacker/helper.rb | 6 +++++- test/helper_test.rb | 7 +++++++ test/test_app/public/packs/manifest.json | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/webpacker/helper.rb b/lib/webpacker/helper.rb index 34849dc8f..7d1580e8e 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..24686a771 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" } From b3654c0473bd0f35a0951f30872f4d0580222f0b Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Sun, 28 Jan 2018 19:31:53 +0000 Subject: [PATCH 2/2] Make rubocop happy --- lib/webpacker/helper.rb | 2 +- test/helper_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/webpacker/helper.rb b/lib/webpacker/helper.rb index 7d1580e8e..54e106dc2 100644 --- a/lib/webpacker/helper.rb +++ b/lib/webpacker/helper.rb @@ -69,7 +69,7 @@ def stylesheet_pack_tag(*names, **options) private def stylesheet?(name) - File.extname(name) == '.css' + File.extname(name) == ".css" end def sources_from_pack_manifest(names, type:) diff --git a/test/helper_test.rb b/test/helper_test.rb index 24686a771..85d7a789d 100644 --- a/test/helper_test.rb +++ b/test/helper_test.rb @@ -17,7 +17,7 @@ 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")