How can I import only one icon from fontawesome?

雨燕双飞 提交于 2021-02-10 11:01:12

问题


I'm searching keyboard-arrow-down icon for my Expansion Panel from vuetify

I have installed

"devDependencies": {
    "@fortawesome/fontawesome-free": "^5.5.0",
}

fontawesome-free, but I think it installed all icons and fonts

So Is there are way to import only one icon (keyboard-arrow-down)?

I've searched my node-modules, but I couldn't find it.

Here's my code.

import Vuetify from 'vuetify'
import '@fortawesome/fontawesome-free/css/all.css'

Vue.use(Vuetify, {
  iconfont: 'fa'
 })

回答1:


Install the dependencies:

npm i --save @fortawesome/fontawesome-svg-core \
npm i --save @fortawesome/free-solid-svg-icons \
npm i --save @fortawesome/vue-fontawesome

Import individual icons:

import { library } from '@fortawesome/fontawesome-svg-core'
import { faCoffee } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'

library.add(faCoffee)

Vue.component('font-awesome-icon', FontAwesomeIcon)

Use it:

<template>
  <div id="app">
    <font-awesome-icon icon="coffee" />
  </div>
</template>

Vue.js reference documentation

Update

Bundle sizes for reference using Vue CLI 3:

1. Single Icon

File                                 Size               Gzipped

dist/js/chunk-vendors.0ce8e3e3.js    135.62 KiB         46.03 KiB
dist/js/app.d98fb35c.js              2.30 KiB           1.13 KiB

2. All Icons

File                                 Size               Gzipped

dist/js/chunk-vendors.7833710c.js    767.94 KiB         249.05 KiB
dist/js/app.b7f38b90.js              2.36 KiB           1.17 KiB


来源:https://stackoverflow.com/questions/53298778/how-can-i-import-only-one-icon-from-fontawesome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!