Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the registration of the Engines' assets path in propshaft #43

Merged
merged 1 commit into from
Dec 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/propshaft/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
require "rails"
require "rails/railtie"
require "active_support/ordered_options"

# FIXME: There's gotta be a better way than this hack?
class Rails::Engine < Rails::Railtie
initializer "propshaft.append_assets_path", group: :all do |app|
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
end
end

module Propshaft
class Railtie < ::Rails::Railtie
config.assets = ActiveSupport::OrderedOptions.new
Expand All @@ -23,6 +13,15 @@ class Railtie < ::Rails::Railtie
]
config.assets.sweep_cache = Rails.env.development?

# Register propshaft initializer to copy the assets path in all the Rails Engines.
# This makes possible for us to keep all `assets` config in this Railtie, but still
# allow engines to automatically register their own paths.
Rails::Engine.initializer "propshaft.append_assets_path", group: :all do |app|
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
end

config.after_initialize do |app|
config.assets.output_path ||=
Pathname.new(File.join(app.config.paths["public"].first, app.config.assets.prefix))
Expand Down