Nuxt.js: Include font files: use /static or /assets

Merc picture Merc · Jun 4, 2018 · Viewed 18.4k times · Source

I know some posts in the nuxt.js github repo cover this a bit, but I would like to know what is the correct way to use font-files in nuxt.js.

So far we had them in the /static/fonts directory, but other people use assets to store the font files. What are the differences? Is one of the options better and if so, why?

Also there are different ways to include them. Would a path like this be correct:

@font-face {
  font-family: 'FontName';
  font-weight: normal;
  src: url('~static/fonts/font.file.eot'); /* IE9 Compat Mode */
  src: url('~static/fonts/font.file.woff') format('woff'),
       url('~static/fonts/font.file.otf') format('otf'),
       url('~static/fonts/font.file.eot') format('eot');
}

Thanks for some clarification here :D. cheers

J

Answer

Nicolas Pennec picture Nicolas Pennec · Jun 4, 2018

it's very well explained on the official doc: https://nuxtjs.org/guide/assets/

assets\ is reserved for assets to be processed (eg. concat css with webpack)

static\ is useful to expose all static files from the root url (static\img\test.jpg => http://example.fr/img/test.jpg), without any process