Using Ruby 3, Rails 7+ and Sprockets V4 I'm having trouble compiling the css assets from gems.
I've created a gem (as a Rails Engine) and it contains some .css assets in app/assets/stylesheets/my_gem
(note that this directory is located inside the my_gem project not in the main Rails application) and also it has a app/assets/config/my_gem_manifest.js
file that includes the actual .css files I need.
The only way I can use my_gem assets into the main Rails application is to explicitly set the gem's path and manually add the css file on the main Rail application's load path like:
(on main app application.rb )
config.assets.paths << '/usr/local/bundle/gems/my_gem-0.1.7/app/assets/stylesheets/my_gem'
By doing this I can actually require my css without errors but my goal is to add only the "my_gem"'s manifest file and have Sprockets to actually compile the gem's css assets and make it available to the main Rails application.
I've tried also to manually add the directory in which the gem's manifest file lives and even tried to add the manifest file to the precompile list of the main app but without success, like this:
config.assets.paths << '/usr/local/bundle/gems/my_gem-0.1.7/app/assets/config'
config.assets.precompile << "my_gem_manifest.js"
Struggling with this for days! Any help appreciated. Thank you.
Rails::Railtie
Setup:
If you want to use manifest:
https://github.com/rails/sprockets#directives
Rails::Engine
Setup:
Unlike Railtie, Engine takes care of a lot of stuff for you:
Main app
Now you can use your gem/engine assets from the main app:
or you can require files from main app application.css: