The easiest way to add a CDN-hosted font is by inserting it directly into your global head. Add this to your src/main.js
to insert a CDN font:
export default function (Vue, { head }) {
head.link.push({
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css?family=Roboto'
})
}
Self-hosting open source fonts, as explained in the docs:
The Typefaces project has already taken care of scripting all of the Google Fonts and Font Squirrel collections into NPM packages. You can see all of the fonts available in the repo.
Once you know what font you want to use, it's just a simple NPM install. For example, if want to use Open Sans:
npm i -d typeface-open-sans
Then you simply require the package in your ./src/main.js
file:
require('typeface-open-sans')
And you're all done!
It's important to note that the aliases mentioned in the Directory Structure don't work in your <style>
tags because they aren't included into the Webpack bundle, so you need to use a relative path to them.
Given the following directory:
└── src/
├── main.js
├── layouts/
│ └── Default.vue
└── assets/
└── Helvetica.ttf
You would import your font like this from Default.vue
:
<style lang="sass">
@font-face {
font-family: Northwell;
src: url('../assets/Northwell.otf');
font-weight: normal;
}
</style>