Skip to content

Commit 9741885

Browse files
authored
Update fonts documentation. Added clarification, missing import, as well as changes to be compatible with Vite. (#641)
1 parent fe5d18a commit 9741885

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

docs/fonts.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ You can use custom fonts by adding them to the `./public/fonts` directory,
1111
fonts. You will also need to add the `css` file for the font to the
1212
`./app/styles` directory, if your font doesn't come with one (Google Fonts
1313
don't) you can generate one using a tool like
14-
[Transfonter](https://transfonter.org/).
14+
[Transfonter](https://transfonter.org/). Transfonter now has a fonts directory
15+
setting. Set that to `fonts` to have the `url` preset.
1516

16-
You may need to edit the `url` property in the `css` file to point to the
17-
correct location of the font files, that path is relative to the `public`
17+
Verify the `url` in the `css` is relative to the `public`
1818
folder. So it should look something like
1919
`url('/fonts/yourfont/yourfont-200.woff2')`.
2020

@@ -31,14 +31,14 @@ Now you've added your font, there's a few places you need to update to use it.
3131
}
3232
```
3333

34-
2. Add your font to the `fontFamily` property.
34+
2. Import the default theme and add your font to the `fontFamily` property.
3535

3636
```ts
37+
import defaultTheme from 'tailwindcss/defaultTheme.js'
3738
// tailwind.config.ts
3839
extend: {
39-
...
40+
...extendedTheme,
4041
fontFamily: {
41-
...
4242
sans: ['var(--font-sans)', ...defaultTheme.fontFamily.sans],
4343
}
4444
}
@@ -48,14 +48,14 @@ Now you've added your font, there's a few places you need to update to use it.
4848
3. Import your font stylesheet.
4949

5050
```tsx
51-
// root.tsx
52-
import fontStyleSheetUrl from './styles/yourfont.css'
51+
// app/routes/root.tsx
52+
import fontStyleSheetUrl from './styles/yourfont.css?url'
5353
```
5454

5555
Add the font stylesheet to the links array.
5656

5757
```tsx
58-
// root.tsx
58+
// app/routes/root.tsx
5959
...
6060
{ rel: 'preload', href: fontStyleSheetUrl, as: 'style' },
6161
{ rel: 'stylesheet', href: fontStyleSheetUrl },
@@ -64,7 +64,7 @@ Now you've added your font, there's a few places you need to update to use it.
6464
4. Expose and cache your fonts folder.
6565

6666
```ts
67-
// server.ts
67+
// server/index.ts
6868
...
6969
app.use(
7070
'/fonts',

0 commit comments

Comments
 (0)