-
Notifications
You must be signed in to change notification settings - Fork 99
Description
The README says:
you should also consider simply referring to your other CSS files directly, instead of bundling them all into one big file. It's better for caching, and it's simpler to setup. You can refer to other CSS files by expanding the
stylesheet_link_taginapplication.html.erblike so:<%= stylesheet_link_tag "application", "other", "styles", "data-turbo-track": "reload" %>.
Here's what I did:
- Create a new Rails app with
rails new my_app -j esbuild --css tailwind - Create a new CSS file
app/assets/stylesheets/foo.css - Change the
stylesheet_link_taginapplication.html.erblike so:<%= stylesheet_link_tag "application", "foo", "data-turbo-track": "reload" %>
This causes a Sprockets::Rails::Helper::AssetNotPrecompiledError exception with the following error message:
Asset `more.css` was not declared to be precompiled in production.
Declare links to your assets in `app/assets/config/manifest.js`.
//= link foo.css
and restart your server
I can fix the error by editing manifest.js to include the additional stylesheet, e.g. with //= link_directory ../stylesheets .css, but is this the correct approach? The cssbundling-rails gem explicitly removes this line from manifest.js as part of its install task:
cssbundling-rails/lib/install/install.rb
Lines 8 to 9 in 0d06dea
| say "Stop linking stylesheets automatically" | |
| gsub_file "app/assets/config/manifest.js", "//= link_directory ../stylesheets .css\n", "" |
I realize this is probably more of an issue with Sprockets rather than with cssbundling-rails itself, but the boundary's not very clear. What is the correct approach to add additional CSS files when using cssbundling-rails?
- Re-add
//= link_directory ../stylesheets .csstomanifest.js? - Add only the additional CSS files, e.g. with
//= link ../stylesheets/foo.css? - Something else?