Skip to content

Conversation

olivier-thatch
Copy link
Contributor

@olivier-thatch olivier-thatch commented Sep 9, 2025

This PR adds support for Propshaft, the newer Rails asset pipeline (and the default pipeline as of Rails 8).

Basically:

  • for Sprockets projects:
    • Sprockets will bundle all CSS into a single application.css file and all JS into a single application.js file
    • in the view, a conditional check will include application.css and application.js if Propshaft is not being used
  • for Propshaft projects:
    • Propshaft does not bundle files
    • in the view, a conditional check will include all of the CSS and JS files separately if Propshaft is being used

I renamed screen.css.erb to screen-sprockets.css.erb and added a new screen-propshaft.css file, since Propshaft does not support ERB templates for assets, but does support referencing images in CSS (cf. docs).

This is the same approach used by other Rails engines such as blazer, e.g.:

I manually tested this with both Sprockets and Propshaft, and AFAICT everything works as expected.

Closes #129.

@grape-bot
Copy link

grape-bot commented Sep 10, 2025

1 Message
📖 We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!

Generated by 🚫 Danger

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want something more organized where we have assets/stylesheets/grape_swagger_rails/default and assets/stylesheets/grape_swagger_rails/propshaft, separate tests that exercise both with and without propshaft, etc.

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I'm understanding how we are choosing sprockets vs. propshaft.

That said, everything sprockets-specific should end up in a subfolder called sprockets, and everything propshaft in a folder called propshaft. Everywhere anything is required we want to inject the "sprockets" or "propshaft" name and not do ifs.

Also README and CHANGELOG will need updates.

@olivier-thatch olivier-thatch marked this pull request as draft September 11, 2025 23:32
@olivier-thatch olivier-thatch force-pushed the propshaft-compatibility branch 4 times, most recently from bc07313 to a445d08 Compare September 12, 2025 23:42
@olivier-thatch
Copy link
Contributor Author

olivier-thatch commented Sep 12, 2025

@dblock I've updated this PR to remove the Sprockets initialization stuff (moved to #132) and focus purely on adding support for Propshaft.

Unlike Sprockets, Propshaft is not a bundler. All it does is fingerprint assets for cache busting (assets/stylesheets/foo.css -> public/assets/stylesheets/foo-<digest>.css). It doesn't create any new files, and only changes file contents to ensure that assets that references other assets (e.g. a CSS file that uses an image file with url("/assets/background.png")) use the updated filename (url("/assets/background-<digest>.png")).

Propshaft's README does a good job of explaining what it does exactly: https://github.com/rails/propshaft/blob/main/README.md#propshaft

This means that with Propshaft, it's not possible to include a single application.css and application.js. All asset files must be explicitly included as needed.

Unfortunately I don't think there's a good way of deduplicating the list of assets when both Sprockets and Propshaft need to be supported :(

Propshaft does not require any special initialization, as it will automatically include assets from 3rd party gems as long as they follow Rails conventions (app/assets).

@olivier-thatch olivier-thatch marked this pull request as ready for review September 15, 2025 16:17
@dblock dblock merged commit b173496 into ruby-grape:master Sep 16, 2025
20 of 23 checks passed
@dblock
Copy link
Member

dblock commented Sep 16, 2025

Merged, thanks Olivier! Want to help co-maintain this gem? Maybe make the next release? Email me dblock at dblock dot org if you have interest.

@olivier-thatch olivier-thatch deleted the propshaft-compatibility branch September 16, 2025 16:30
@olivier-thatch
Copy link
Contributor Author

Thanks for merging! And sure, I wouldn't mind helping maintain the gem :) Can you add my non-corporate account @olivierbellone as a maintainer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the Rails 8 support
3 participants