vue-cli-plugin-fontawesome
Using Font Awesome 5 in a Vue.js project is already
pretty simple, but you still have to work with a verbose and repetitive syntax
in order to benefit from tree-shaking and include only the needed icons in the
final bundle. This tiny plugin allows you to manage your icon sets directly
from your vue.config.js
file, avoiding boilerplate code and error-prone
repetitions.
Installation
vue add @cheap-glitch/fontawesome
The install prompt will ask you which icon sets you want to be automatically
included in your package.json
and downloaded. You can leave all the options
unchecked if you'd rather add them manually. Regardless of your choices, two
packages will always be added and downloaded:
No other file will be modified during the installation process.
Note: if you want to install pro icon sets, make sure you have a .npmrc
file
at the root of your project with your token in it, otherwise the installation
will fail (cf. "Installing the Pro version of Font
Awesome").
Usage
module.exports = {
pluginOptions: {
fontawesome: {
component: 'fa-icon',
components: {
icon: 'fa-icon',
layers: 'fa-layers',
layersText: 'fa-layers-text',
},
imports: [
{
set: '@fortawesome/free-solid-svg-icons',
icons: [
'faUser',
'faFileUpload',
'faFrenchFries',
]
},
{
set: 'pro-duotone-svg-icons',
icons: [
'guitar',
'fax',
'fastForward',
'spider-black-widow',
'dumpster fire',
]
},
{
set: 'free-brands',
icons: [
'faVuejs',
'creative-commons'
'Fort Awesome',
]
},
'pro-light',
]
}
}
}
You can then use the Font Awesome component in your templates. For more info,
see here.
Changelog
See the full changelog here.
Acknowledgements
This plugin depends on the awesome webpack-inject-plugin.
This plugin is heavily inspired by its Nuxt.js counterpart, nuxt-fontawesome.
License
This project is licensed under the ISC license.