Configuration
Propshaft is configured in your Rails application via config.assets. These options are typically set in config/application.rb or environment-specific files like config/environments/development.rb.
Here are the available configuration options:
config.assets.paths
- Description: An array of directories where Propshaft will look for assets. By default, Rails automatically adds
app/assets,lib/assets, andvendor/assetsfrom both the application and any gems/engines. - Type:
ArrayofStringorPathname - Default:
[](populated by initializers)
config.assets.excluded_paths
- Description: An array of directories to exclude from the load path. This is useful if a directory in
config.assets.pathscontains source files you don't want to be served directly, such as Sass partials. - Type:
ArrayofStringorPathname - Default:
[] - Example:
config.assets.excluded_paths << Rails.root.join("app/assets/stylesheets")
config.assets.version
- Description: A string that is incorporated into the digest hash for all assets. Changing this value will cause all assets to be re-digested, effectively busting all caches.
- Type:
String - Default:
"1"
config.assets.prefix
- Description: The URL path where assets will be served from.
- Type:
String - Default:
"/assets"
config.assets.output_path
- Description: The file system path where precompiled assets will be written.
- Type:
Pathname - Default:
Rails.root.join("public", config.assets.prefix)(e.g.,public/assets)
config.assets.manifest_path
- Description: The full path to the asset manifest file.
- Type:
Pathname - Default:
config.assets.output_path.join(".manifest.json")
config.assets.compilers
- Description: An array of compiler definitions. Each definition is a two-element array containing the MIME type and the compiler class.
- Type:
Arrayof[String, Class] - Default:
[ [ "text/css", Propshaft::Compiler::CssAssetUrls ], [ "text/css", Propshaft::Compiler::SourceMappingUrls ], [ "text/javascript", Propshaft::Compiler::JsAssetUrls ], [ "text/javascript", Propshaft::Compiler::SourceMappingUrls ], ]
config.assets.integrity_hash_algorithm
- Description: The cryptographic hash algorithm to use for Subresource Integrity (SRI). Set to
nilorfalseto disable. - Type:
String("sha256","sha384","sha512") ornil - Default:
nil
config.assets.quiet
- Description: Suppress logger output for asset requests in development.
- Type:
Boolean - Default:
false
config.assets.server
- Description: A boolean indicating whether to mount the Propshaft development server middleware.
- Type:
Boolean - Default:
Rails.env.development? || Rails.env.test?
Performance Tuning
For applications with a large number of assets, you can improve development-mode performance by using an evented file watcher. First, add the listen gem to your Gemfile:
group :development do
gem "listen"
end
Then, configure Propshaft to use it in config/environments/development.rb:
config.file_watcher = ActiveSupport::EventedFileUpdateChecker