Skip to content

Commit

Permalink
Add excluded paths
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Feb 10, 2022
1 parent 2585491 commit c669e39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ With Rails 7+, you can start a new application with propshaft using `rails new m

## Usage

Propshaft makes all the assets from all the paths it's been configured with through `config.assets.paths` available for serving and will copy all of them into `public/assets` when precompiling. This is unlike Sprockets, which did not copy over assets that hadn't been explicitly included in one of the bundled assets.
Propshaft makes all the assets from all the paths it's been configured with through `config.assets.paths` available for serving and will copy all of them into `public/assets` when precompiling. This is unlike Sprockets, which did not copy over assets that hadn't been explicitly included in one of the bundled assets.

You can however exempt directories that have been added through the `config.assets.excluded_paths`. This is useful if you're for example using `app/assets/stylesheets` exclusively as a set of inputs to a compiler like Dart Sass for Rails, and you don't want these input files to be part of the load path.

These assets can be referenced through their logical path using the normal helpers like `asset_path`, `image_tag`, `javascript_include_tag`, and all the other asset helper tags. These logical references are automatically converted into digest-aware paths in production when `assets:precompile` has been run (through a JSON mapping file found in `public/assets/.manifest.json`).

Expand Down
9 changes: 6 additions & 3 deletions lib/propshaft/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
module Propshaft
class Railtie < ::Rails::Railtie
config.assets = ActiveSupport::OrderedOptions.new
config.assets.paths = []
config.assets.prefix = "/assets"
config.assets.compilers = [
config.assets.paths = []
config.assets.excluded_paths = []
config.assets.prefix = "/assets"
config.assets.compilers = [
[ "text/css", Propshaft::Compilers::CssAssetUrls ],
[ "text/css", Propshaft::Compilers::SourceMappingUrls ],
[ "text/javascript", Propshaft::Compilers::SourceMappingUrls ]
Expand All @@ -21,6 +22,8 @@ class Railtie < ::Rails::Railtie
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|
Expand Down

0 comments on commit c669e39

Please sign in to comment.