iTranslated by AI
Speed Up Web Font Loading in Nuxt.js with @nuxtjs/google-fonts
The other day, this article was trending, and I looked into whether Nuxt.js had a similar feature and found it.
@nuxtjs/google-fonts
@nuxtjs/google-fonts is a Nuxt.js module for Google Fonts. This module has options called download and inject, and by enabling these, you can achieve the same result as Next.js Font Optimizations.
Actually tried it
Here is the repository I used for testing.
I added the following settings to nuxt.config.js.
buildModules: [
['@nuxtjs/google-fonts', { families: { Inter: true }, display: 'block', download: true, inject: true }]
],
When you run nuxt build/generate in this state, font files and a CSS file that loads them are generated locally.
If the inject option is enabled, the generated CSS file is automatically loaded as a global CSS.
Conclusion
When I saw the original Next.js article, I thought about making a similar feature myself if Nuxt.js didn't have one, but it already existed.
While Next.js uses a mechanism to analyze HTML and automatically replace things, Nuxt.js provides it as a module with an option to handle inline expansion, showing a difference in philosophy. Personally, I prefer the Nuxt.js approach as it is easier to understand.
Discussion