Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts not loading with dart sass in Rails 7 #222

Open
michaelrevans opened this issue Oct 28, 2023 · 6 comments
Open

Fonts not loading with dart sass in Rails 7 #222

michaelrevans opened this issue Oct 28, 2023 · 6 comments

Comments

@michaelrevans
Copy link

I have a Rails project that uses dartsass for SASS to CSS compilation.

Having followed through the installation instructions, the fonts are missing and it's giving a simple routing error in the rails server logs:

ActionController::RoutingError (No route matches [GET] "/webfonts/fa-solid-900.ttf"):

and the same for the woff2 file.

Unsurprisingly, when trying to use the fonts in a view (using ERB), it's not showing any content and the browser console displays the a similar 404 error:

GET http://localhost:3000/webfonts/fa-brands-400.ttf net::ERR_ABORTED 404 (Not Found)
@Ozkee
Copy link

Ozkee commented Dec 4, 2023

Did you find the solution?
Here it is, in your application.scss:
@use 'font-awesome' with ($fa-font-path: 'font-awesome');

@joshuacronemeyer
Copy link

@Ozkee thanks for this. nothing worked until i found this issue and your comment.

@joshuacronemeyer
Copy link

joshuacronemeyer commented Dec 29, 2023

Actually @Ozkee's suggestion got the icons working for me, for example when i do

<%= icon('fa-brands', 'font-awesome')%>

everything works, but I too am seeing some 404s in the console. Not causing me issues but wondering if i'm still missing something.

Started GET "/webfonts/fa-solid-900.woff2" for ::1 at 2023-12-29 09:40:41 -0600

ActionController::RoutingError (No route matches [GET] "/webfonts/fa-solid-900.woff2"):

Started GET "/webfonts/fa-solid-900.ttf" for ::1 at 2023-12-29 09:40:41 -0600

ActionController::RoutingError (No route matches [GET] "/webfonts/fa-solid-900.ttf"):

Started GET "/webfonts/fa-regular-400.woff2" for ::1 at 2023-12-29 09:40:41 -0600

ActionController::RoutingError (No route matches [GET] "/webfonts/fa-regular-400.woff2"):

Started GET "/webfonts/fa-regular-400.ttf" for ::1 at 2023-12-29 09:40:41 -0600

ActionController::RoutingError (No route matches [GET] "/webfonts/fa-regular-400.ttf"):

i checked and using an fa-regular icon is working.

@fschiefelbein
Copy link

fschiefelbein commented Feb 27, 2024

@joshuacronemeyer, I have changed _variables.scss from
$fa-font-path : "../webfonts" !default;
to
$fa-font-path : "assets/font-awesome/webfonts" !default;

and fixed all routing errors. Just check your path matches.
With this change you don't need to add the @use statement to your application.scss

@joshuacronemeyer
Copy link

ok interesting @fschiefelbein so are you rebuilding a gem from your own fork or are you overriding this somehow in your app. I see the file and line you've changed, just wondering what's the best way to incorporate it. I wonder if you made a PR for this if they would merge it

@fschiefelbein
Copy link

I came across this issue without using the gem, I am just using dartsass-rails and hosting fontawesome files. I changed my _varialble.scss file in my app. I didn't make a PR for this.

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

No branches or pull requests

4 participants