๐Ÿ‘ฉ‍๐Ÿ’ป/Vue

[fontawesome] vue.js์—์„œ free-brands-svg-icons ์“ฐ๊ธฐ

ํ•œ๋‚˜ 2020. 12. 29. 20:41

vue ํ”„๋กœ์ ํŠธ์—์„œ font-awesome์„ ์“ฐ๊ธฐ.

 

$ yarn add -D @fortawesome/fontawesome-svg-core 
$ yarn add -D @fortawesome/free-solid-svg-icons (optional)
$ yarn add -D @fortawesome/free-brands-svg-icons (optional)
$ yarn add -D @fortawesome/vue-fontawesome

optional์ด ์•„๋‹Œ ์ฒซ ๋ฒˆ์งธ, ๋„ค ๋ฒˆ์งธ๋Š” ํ•„์ˆ˜๋กœ ๋‹ค์šด๋ฐ›์•„์ค€๋‹ค. ๋‚˜๋Š” ์†Œ์…œ ๋กœ๊ทธ์ธ์„ ์œ„ํ•œ ๋ฒ„ํŠผ์„ ๋งŒ๋“ค ๋•Œ ๋“ค์–ด๊ฐˆ github, google icon์„ ์“ฐ๊ธฐ ์œ„ํ•ด ์„ธ ๋ฒˆ์งธ free-brands-svg-icons๋ฅผ ๋จผ์ € ๋ฐ›์•„์ฃผ์—ˆ๋‹ค. ๋ฐ›๊ณ ์ž ํ•˜๋Š” ์•„์ด์ฝ˜์ด ์–ด๋–ค ์นดํ…Œ๊ณ ๋ฆฌ์— ์žˆ๋Š”์ง€๋Š”, solid, regular, light... brands ๋“ฑ์˜ ๊ตฌ๋ถ„์œผ๋กœ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

๊ฐ€๋ น, ์•„๋ž˜ ์•„์ด์ฝ˜์˜ ๊ฒฝ์šฐ fab๋กœ, brands์— ์†ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

๋‹ค์šด์„ ๋ฐ›์€ ๋’ค์—๋Š”, ์•„์ด์ฝ˜ ์‚ฌ์šฉ์„ ์ข€ ๋” ์‰ฝ๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ํ”„๋กœ์ ํŠธ์˜ ๋ฃจํŠธ ํด๋”์— fontAwesomeIcon.js๋ผ๋Š” ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์ค€๋‹ค.

import Vue from "vue";

// ํ•„์ˆ˜๋กœ ๋‹ค์šด ๋ฐ›๊ณ  & import ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { library } from "@fortawesome/fontawesome-svg-core";

// ํ•„์š”ํ•œ ์•„์ด์ฝ˜๋งŒ ๊ทธ๋•Œ ๊ทธ๋•Œ import ํ•ด์ค€๋‹ค.
import { faGithub, faGoogle } from "@fortawesome/free-brands-svg-icons";
import { faSignInAlt, faSignOutAlt } from "@fortawesome/free-solid-svg-icons";

// library์— ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.
library.add(faGithub, faGoogle);
library.add(faSignInAlt, faSignOutAlt);

Vue.component("font-awesome-icon", FontAwesomeIcon);

 

์ „์—ญ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๋„๋ก, main.js์— import ์‹œ์ผœ์ค€๋‹ค.

// main.js

import Vue from "vue";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import App from "./App.vue";
import router from "./router";
import store from "./store";

// fontAwesomeIcon์„ import ์‹œ์ผœ์ค€๋‹ค.
import "@/fontAwesomeIcon.js";

Vue.config.productionTip = false;

Vue.use(ElementUI);

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");

์ด์ œ ์‹ค์ œ ์ปดํฌ๋„ŒํŠธ์—์„œ ์‚ฌ์šฉํ•  ๋•Œ, free-solid-svg-icon์˜ ๊ฒฝ์šฐ์—๋Š” ์•„๋ž˜์ฒ˜๋Ÿผ ์จ์ฃผ๋ฉด ๋œ๋‹ค.

 

<router-link to="/login"><font-awesome-icon icon="sign-in-alt" />Login</router-link>

 

free-brands-svg-icon์˜ ๊ฒฝ์šฐ์—๋Š” ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ ์‹œ๋„ํ•˜๋‹ˆ ์ ์šฉ์ด ์•ˆ ๋˜์–ด ๊ฒ€์ƒ‰ํ•˜๋‹ค๊ฐ€, ์ด๊ณณ์˜ ๊ธ€ ๋•๋ถ„์— ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

 

// ex) login.vue

<el-button type="primary" plain @click="socialLogin('google')">
	<font-awesome-icon :icon="['fab', 'google']" /> Login With Google
</el-button>

 

์‚ฌ์‹ค ๊ณต์‹ ๋ฌธ์„œ์—์„œ ์•„๋ž˜์ฒ˜๋Ÿผ ์–ธ๊ธ‰์ด ๋˜์–ด ์žˆ๊ธด ํ–ˆ๋‹ค. solid style๋„ : bind ์ด์šฉํ•ด ์ ์„ ์ˆ˜ ์žˆ๋‹ค! ํ•˜์ง€๋งŒ, brand icons๋Š” ์ฒซ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ๋Š” ํ•  ์ˆ˜ ์—†์–ด์„œ ์ ์šฉ์ด ์•ˆ ๋˜์—ˆ๋˜ ๊ฒƒ. solid style๋งŒ short-hand ๋ฐฉ์‹์œผ๋กœ, prefix๋ฅผ ์ƒ๋žตํ•ด๋„ fas ์นดํ…Œ๊ณ ๋ฆฌ๋กœ ์—ฌ๊ฒจ์ง„๋‹ค.

 

<!-- The solid style is implicit -->
<font-awesome-icon icon="user-secret" />

<!-- It's better to be explicit -->
<!-- Don't forget to bind the property with ":" (we forget all the time!) -->
<font-awesome-icon :icon="['fas', 'user-secret']" />

 

 

์ ์šฉ ์˜ˆ 1
์ ์šฉ ์˜ˆ 2

+ font-awesome-icon์˜ ๊ฒฝ์šฐ size="2x" ์ฒ˜๋Ÿผ ์‚ฌ์ด์ฆˆ ์˜ต์…˜์„ ๋ณ„๋„๋กœ ๊ฐ–๋Š”๋‹ค.

+ ์œ„๋Š” ๋ฌด๋ฃŒ ๋ฒ„์ „ ์•„์ด์ฝ˜ ์‚ฌ์šฉ ์˜ˆ.

 

์ฐธ๊ณ 

uxgjs.tistory.com/205

www.npmjs.com/package/@fortawesome/vue-fontawesome