question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docs around loading fonts and global CSS imports

See original GitHub issue

I just went through a quite painful setup of fonts for my project - first I was trying to include font files manually from google webfonts helper. But the @font-face definitions were being removed somewhere during css optimization in build. I ended up looking into the example project, where I discovered that fontsource exists, and that fonts are loaded with import "../app.css", which I didn’t find documented anywhere. Also I faced another issue with using fontsource customizable sass mixins, as the referenced files weren’t being loaded from the tilde path so I had to override $fontDir: "@fontsource/#{Roboto.$fontId}/files"

I’ll be very happy to contribute docs for all of this to avoid this pain for others in the future, but first I’d like to check if there’s a best practice established, get some info about importing css files in js, and where actually to put this so the docs page doesn’t grow infinitely with various best-practices and tips

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:8
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
owtotwocommented, Sep 15, 2021

@danielrob

When doing so in my case SvelteKit was preserving the @font-face definitions, but the actual font assets referenced in the url() call in the @font-face rule weren’t being carried across from the static folder during the build (adaptor-static). The dev build was fine.

I encountered the same problem. svelte-kit dev is fine, but svelte-kit build will not put the assets(image and font files) referenced in my style by url(...) into the /_app/assets/pages/... folder.

The browser reported an error as GET http://localhost:3000/_app/assets/pages/img/background.png 404 (Not Found).

The reason for my error is that I set the url(img/background.png) in <style> tag as a RELATIVE path instead of an ABSOLUTE path. @font-face is the same situation in my project.

After I changed the relative path to the absolute path, that is, url(img/background.png) => url(/img/background.png), the problem seemed to be solved. (url(...) in @font-face is the same)

Maybe you are not encountering this problem, but I still hope that other new users of sveltekit who encounter similar situations can receive a little help.

5reactions
ayuhitocommented, Jun 2, 2021

If this does go through and is approved, please do tag me in the PR. I’ll happily review the content and link the final page in the Guides section of the Fontsource docs since I’ve never personally worked with Svelte but still wish to support the community.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Import Google Fonts in CSS File - W3docs
Find the font and click it (a card with the font), then, click "+ Select this style". · Click "Embed" and choose <link>...
Read more >
How To Load and Use Custom Fonts with CSS | DigitalOcean
In this tutorial, you will try out examples of loading fonts onto your website. You will use the font stack, a rank ordering...
Read more >
import - CSS: Cascading Style Sheets - MDN Web Docs
The @import CSS at-rule is used to import style rules from other valid stylesheets. An @import rule must be defined at the top...
Read more >
How to import Google Web Font in CSS file? - Stack Overflow
Google Fonts can automatically generate the @import directive for you. Once you have chosen a font, click the (+) icon next to it....
Read more >
How to use @font-face in CSS
The @font-face rule allows custom fonts to be loaded on a webpage. Once added to a stylesheet, the rule instructs the browser to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found