How do we use nuxt/fonts with local otf files ?
Hi guys! I have to use local font files in my nuxt project. I tried to make an configuration like this :
I have move all my necessary font files in
/public/_fonts
directory, but when I apply font on my element it doesn't work:
/public/_fonts/My Font.otf
font-family: 'My Font'
3 Replies
Hi @David. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in the knowledge sources, I don't have specific details about using
@nuxt/fonts
module with local OTF files. However, I can provide you with an alternative approach to use local fonts in your Nuxt project based on the available information.
Here's how you can use local font files in your Nuxt project:
1. Place your font files in the public/
directory. In your case, you've already done this by putting them in /public/_fonts
.
2. Create a CSS file in your assets/
directory, for example assets/css/fonts.css
, and define your font face:
3. In your nuxt.config.ts
, add this CSS file to the global styles:
4. Now you can use your font in your components or global CSS:
This approach is based on the information from the Nuxt documentation on styling and working with fonts (https://nuxt.com/docs/getting-started/styling#working-with-fonts).
If you specifically want to use the @nuxt/fonts
module, you might need to check its documentation for details on how to configure local fonts, as the provided knowledge sources don't contain information about this specific module's usage with local fonts.
Remember that when using local fonts, make sure the font file names and paths are correct, and that you're using the appropriate format in your @font-face
declaration (opentype
for OTF files).
If this doesn't solve your issue, you might want to check if there's a bug or limitation with the @nuxt/fonts
module. In that case, you can refer to the Nuxt bug reporting guidelines (https://nuxt.com/docs/community/reporting-bugs) for next steps.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@556083802628161546> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
But I said that I use nuxt/fonts module