diff --git a/lib/propshaft/railtie.rb b/lib/propshaft/railtie.rb index 8f62e2e..101a286 100644 --- a/lib/propshaft/railtie.rb +++ b/lib/propshaft/railtie.rb @@ -32,6 +32,9 @@ class Railtie < ::Rails::Railtie end config.after_initialize do |app| + # Prioritize assets from within the application over assets of the same path from engines/gems. + config.assets.paths.sort_by! { |path| path.to_s.start_with?(Rails.root.to_s) ? 0 : 1 } + config.assets.relative_url_root ||= app.config.relative_url_root config.assets.output_path ||= Pathname.new(File.join(app.config.paths["public"].first, app.config.assets.prefix)) diff --git a/test/dummy/app/views/sample/load_real_assets.html.erb b/test/dummy/app/views/sample/load_real_assets.html.erb index 81b82c7..8b3594b 100644 --- a/test/dummy/app/views/sample/load_real_assets.html.erb +++ b/test/dummy/app/views/sample/load_real_assets.html.erb @@ -4,3 +4,4 @@
Find me in app/views/sample/load_real_assets.html.erb
<%= javascript_include_tag "hello_world" %> +<%= javascript_include_tag "actioncable" %> diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index fb160a1..96f7176 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -11,7 +11,7 @@ # require "action_mailbox/engine" # require "action_text/engine" require "action_view/railtie" -# require "action_cable/engine" +require "action_cable/engine" # require "sprockets/railtie" require "rails/test_unit/railtie" diff --git a/test/dummy/lib/assets/javascripts/actioncable.js b/test/dummy/lib/assets/javascripts/actioncable.js new file mode 100644 index 0000000..f2b14cd --- /dev/null +++ b/test/dummy/lib/assets/javascripts/actioncable.js @@ -0,0 +1 @@ +console.log("actioncable.js") diff --git a/test/propshaft_integration_test.rb b/test/propshaft_integration_test.rb index b2eeecc..cb3a66a 100644 --- a/test/propshaft_integration_test.rb +++ b/test/propshaft_integration_test.rb @@ -13,6 +13,12 @@ class PropshaftIntegrationTest < ActionDispatch::IntegrationTest assert_select 'script[src="/assets/hello_world-888761f8.js"]' end + test "should prioritize app assets over engine assets" do + get sample_load_real_assets_url + + assert_select 'script[src="/assets/actioncable-2e7de4f9.js"]' + end + test "should find app styles via glob" do get sample_load_real_assets_url