Next.js Discord

Discord Forum

Using next/font/local with Base64 strings

Answered
Swedish Elkhound posted this in #help-forum
Open in Discord
Swedish ElkhoundOP
I need to use fonts in base64 and I was thinking to do something like this:

import { Font } from './Font';
import localFont from 'next/font/local'

const myFont = localFont({
  src: `data:font/woff2;base64,${Font} `,
  display: 'swap',
})

Font.js is just a export of the base64 string.

The error Font loader values must be explicitly written literals.

Any ideas?
Answered by riský
by using next/font it will make it a file (if it was a valid import) - so i think it makes sense to only support file locations
View full answer

9 Replies

Swedish ElkhoundOP
any soul?
is there a reason why you don't have it saved as a file?
Swedish ElkhoundOP
the client don't want to expose the typeface
its custom
by using next/font it will make it a file (if it was a valid import) - so i think it makes sense to only support file locations
Answer
but base64 isn't going to stop it from being exposed
Swedish ElkhoundOP
I understand
its the same as file...
@Swedish Elkhound did you get this working (/did you make it a file)