Skip to content

What is the recommended way to use a different font? #113

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

Closed
odinsride opened this issue Dec 23, 2021 · 3 comments
Closed

What is the recommended way to use a different font? #113

odinsride opened this issue Dec 23, 2021 · 3 comments

Comments

@odinsride
Copy link

Coming from the webpacker/yarn method of adding @fontsource packages for fonts, that doesn't seem to work with this gem. For now, I've resorted to linking to the font externally from Google Fonts. Do I simply need to download the font into assets (and configure CSS accordingly) if I want to self-host it?

@dixpac
Copy link
Contributor

dixpac commented Dec 23, 2021

@odinsride exactly. You should download fonts and place them inside the app/assets/fonts/ and hook the font with the tailwind css something like this

This engine already configures the inter-font so maybe this could help you:
https://github.com/rails/tailwindcss-rails/tree/main/app/assets/fonts
https://github.com/rails/tailwindcss-rails/blob/main/lib/install/tailwind.config.js#L12

Hope this helps 😄

@odinsride
Copy link
Author

Thanks for clearing that up!

@dhh dhh closed this as completed Jan 16, 2022
@dp6ai
Copy link

dp6ai commented Feb 10, 2022

For anyone who comes back to this, the following worked for me:

  • Add your font files under app/assets/fonts/xxxx.otf
  • Create a new stylesheet app/assets/stylesheets/xxxx-font.css with
    @font-face { font-family: 'X Family Name; src: url('xxxx.otf') format('opentype'); }
  • Add this to assets.rb
    Rails.application.config.assets.precompile += %w( xxxx-font.css )
  • Add this to tailwind.config.js
    my-font: ['X Family Name', ...defaultTheme.fontFamily.sans],
  • Use in your css
    <span class="my-fon">This should work!</span>

HTH

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