You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
stylesheet_pack_tag and stylesheet_packs_with_chunks_tag should NOT raise exception if the pack has no CSS - solves webpacker can't find application.css
#3022
Closed
feliperaul opened this issue
May 17, 2021
· 0 comments
I'm willing to issue a pull request but I'd like to have some feedback from the maintainers first.
This morning I got bit in production by the Webpacker::Manifest::MissingEntryError due to importing packs that didn't have any CSS imported.
Given how much activity and votes #2071 still generates (in May 2021) I think the developer experience can be improved, because it's causing a lot of pain and I see people fiddling with solutions like "always ensure you import at least one empty css file" flying around .
The problem is:
The default extract_css config in webpacker.yml in development and test (!) envs is false, so it will only bite in production; we must avoid these kinds of errors at all costs.
It shouldn't be up to the developer to know if the imported packs have or don't have any CSS being imported; specially in large packs, it's very difficult to follow the graph to check them all, and, again, if someone adds a new pack to the import that doesn't have any CSS, it will only explode in production;
I solved my issue by creating a service object that reads manifest.json (in real time in development to avoid server restarts, but totally memoized in production for max performance) and filters out any packs that don't have any css attached with them.
Replace in your layouts all stylesheet_packs_with_chunks_tag with this new method we'll create, named safe_stylesheet_packs_with_chunks_tag:
I'm willing to issue a pull request but I'd like to have some feedback from the maintainers first.
This morning I got bit in production by the
Webpacker::Manifest::MissingEntryError
due to importing packs that didn't have any CSS imported.Given how much activity and votes #2071 still generates (in May 2021) I think the developer experience can be improved, because it's causing a lot of pain and I see people fiddling with solutions like "always ensure you import at least one empty css file" flying around .
The problem is:
extract_css
config inwebpacker.yml
in development and test (!) envs isfalse
, so it will only bite in production; we must avoid these kinds of errors at all costs.I solved my issue by creating a service object that reads manifest.json (in real time in development to avoid server restarts, but totally memoized in production for max performance) and filters out any packs that don't have any css attached with them.
Replace in your layouts all
stylesheet_packs_with_chunks_tag
with this new method we'll create, namedsafe_stylesheet_packs_with_chunks_tag
:Define this in your ApplicationHelper:
app/services
(create folder if it doesn't exist), create thiswebpacker_packs_service.rb
file:The text was updated successfully, but these errors were encountered: