require "rails" require "active_support/ordered_options" require "propshaft/quiet_assets" module Propshaft class Railtie < ::Rails::Railtie config.assets = ActiveSupport::OrderedOptions.new config.assets.paths = [] config.assets.excluded_paths = [] config.assets.version = "1" config.assets.prefix = "/assets" config.assets.quiet = false config.assets.compilers = [ [ "text/css", Propshaft::Compilers::CssAssetUrls ], [ "text/css", Propshaft::Compilers::SourceMappingUrls ], [ "text/javascript", Propshaft::Compilers::SourceMappingUrls ] ] config.assets.sweep_cache = Rails.env.development? config.assets.server = Rails.env.development? || Rails.env.test? config.assets.host = nil # 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) app.config.assets.paths = app.config.assets.paths.without(Array(app.config.assets.excluded_paths).collect(&:to_s)) end config.after_initialize do |app| config.assets.host = app.config.asset_host config.assets.output_path ||= Pathname.new(File.join(app.config.paths["public"].first, app.config.assets.prefix)) app.assets = Propshaft::Assembly.new(app.config.assets) if config.assets.server app.routes.prepend do mount app.assets.server => app.assets.config.prefix end end ActiveSupport.on_load(:action_view) do include Propshaft::Helper end if config.assets.sweep_cache ActiveSupport.on_load(:action_controller_base) do before_action { Rails.application.assets.load_path.cache_sweeper.execute_if_updated } end end end initializer "propshaft.logger" do Propshaft.logger = config.assets.logger || Rails.logger end initializer :quiet_assets do |app| if app.config.assets.quiet app.middleware.insert_before ::Rails::Rack::Logger, Propshaft::QuietAssets end end rake_tasks do load "propshaft/railties/assets.rake" end # Compatibility shiming (need to provide log warnings when used) config.assets.precompile = [] config.assets.debug = nil config.assets.compile = nil config.assets.css_compressor = nil config.assets.js_compressor = nil end end