Skip to content

Commit c7d5542

Browse files
committed
Improve the registration of the Engines' assets path in propshaft
1 parent 4b072f7 commit c7d5542

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

lib/propshaft/railtie.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
require "rails"
2-
require "rails/railtie"
32
require "active_support/ordered_options"
43

5-
# FIXME: There's gotta be a better way than this hack?
6-
class Rails::Engine < Rails::Railtie
7-
initializer "propshaft.append_assets_path", group: :all do |app|
8-
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
9-
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
10-
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
11-
end
12-
end
13-
144
module Propshaft
155
class Railtie < ::Rails::Railtie
166
config.assets = ActiveSupport::OrderedOptions.new
@@ -23,6 +13,15 @@ class Railtie < ::Rails::Railtie
2313
]
2414
config.assets.sweep_cache = Rails.env.development?
2515

16+
# Register propshaft initializer to copy the assets path in all the Rails Engines.
17+
# This makes possible for us to keep all `assets` config in this Railtie, but still
18+
# allow engines to automatically register their own paths.
19+
Rails::Engine.initializer "propshaft.append_assets_path", group: :all do |app|
20+
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
21+
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
22+
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
23+
end
24+
2625
config.after_initialize do |app|
2726
config.assets.output_path ||=
2827
Pathname.new(File.join(app.config.paths["public"].first, app.config.assets.prefix))

0 commit comments

Comments
 (0)