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

detect font weights automatically #209

Open
ojvribeiro opened this issue Aug 1, 2024 · 4 comments
Open

detect font weights automatically #209

ojvribeiro opened this issue Aug 1, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@ojvribeiro
Copy link

From my testings, only weights 400 (normal) and 700 (bold) are available out of the box by using the @nuxtjs/tailwindcss module like this:

<span class="font-roboto">...</span> <!-- Works -->

<span class="font-roboto font-bold">...</span> <!-- Works -->

<span class="font-roboto font-medium">...</span> <!-- Doesn't work -->

font-roboto is defined in tailwind.config.

Am I missing something, or do I do have to specify the other weights in the module options?

Copy link

dosubot bot commented Aug 1, 2024

Hello, @ojvribeiro! I'm here to assist you with any questions or issues you have. Let's tackle this one together!

The @nuxtjs/tailwindcss module does not automatically detect all font weights. By default, it may only recognize common weights like 400 (normal) and 700 (bold). To use additional font weights, you need to specify them manually in your CSS using the @font-face rule.

Here's an example of how you can define custom font weights:

@font-face {
  font-family: 'Roboto';
  src: url('/path/to/roboto-regular.woff2') format('woff2'),
       url('/path/to/roboto-regular.woff') format('woff');
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: 'Roboto';
  src: url('/path/to/roboto-bold.woff2') format('woff2'),
       url('/path/to/roboto-bold.woff') format('woff');
  font-weight: 700;
  font-style: normal;
}

@font-face {
  font-family: 'Roboto';
  src: url('/path/to/roboto-medium.woff2') format('woff2'),
       url('/path/to/roboto-medium.woff') format('woff');
  font-weight: 500;
  font-style: normal;
}

You can then use these weights in your Tailwind CSS classes:

<span class="font-roboto">...</span> 
<span class="font-roboto font-bold">...</span> 
<span class="font-roboto font-medium">...</span> 

This approach ensures that all specified font weights are available for use in your project [1].

To continue talking to Dosu, mention @dosu.

@qwerzl
Copy link
Member

qwerzl commented Aug 9, 2024

What bot says is partly correct. @nuxt/fonts just does the @font-face injection for you, please refer to this tailwind docs for instructions on using different font weights.

@ojvribeiro
Copy link
Author

ojvribeiro commented Aug 9, 2024

@qwerzl I think my question remains: can the module detect font weights besides 400 and 700?

As I showed in my code example, weights like font-medium or font-semibold don't work out of the box (unless I explicitly set them on nuxt.config). Only font-bold (and the default font-normal) seem to work without explicit configuration.

I created this repro: https://stackblitz.com/edit/nuxt-starter-pngpso?file=app.vue


Edit: by creating the reproduction, I noticed that it doesn't work if I use a custom font-family utility class created in tailwind.config (eg: font-roboto).

with font-roboto:
image

without font-roboto:
image

@yb
Copy link

yb commented Aug 14, 2024

Hi @ojvribeiro , I noticed the same behavior. I even suspected it was because the download of the font file failed. 😂😂😂

Now I added the configuration about font weight in the nuxt.config.ts, which solved the problem.

  fonts: {
    defaults: {
      weights: [100, 200, 300, 400, 500, 600, 700, 800, 900],
    },
  },

@danielroe danielroe changed the title [Question] Can the module detect font weights automatically? detect font weights automatically Sep 23, 2024
@danielroe danielroe added the enhancement New feature or request label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants