[]previous and next page

defineFonts

The stylesheet, the variables and the preloads of the given families.

The stylesheet, the variables and the preloads of the given families. Local families are read from publicDir (no network). A { google: [...] } input is resolved at build time: the Google Fonts CSS and files are fetched, cached and vendored into public/fonts/google/, and recorded in fonts.lock.json.

Import#

ts
import { defineFonts } from "@shadow-js/dusk/vite";

Signature#

ts
function defineFonts(
  fonts: Readonly<Record<string, FontDefinition>>,
  options: DefineFontsOptions,
): FontsOutput

function defineFonts(
  input: DefineGoogleFontsInput,
  options: DefineFontsOptions,
): Promise<FontsOutput>

Parameters#

Name Description
input The local families keyed by a name of your choice (for example sans), or { google, local }.
options The public directory, the URL prefix and the Google options.

Returns#

The stylesheet, the preload tags, the variables and the URLs. A promise for the Google input.

Throws#

  • Error when a file is missing or a Google face cannot be loaded; TypeError for a path, a format, a family or a variable name that is not allowed.

Examples#

ts
const fonts = await defineFonts(
  { google: [{ family: "Inter", variable: "--font-sans", weights: [400, 700], subsets: ["latin"], preload: ["latin"] }] },
  { publicDir: join(root, "public") },
);