Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

nuxt 3 font awesome

/**
 * According to the official Font Awesome docs, it's now
 * possible to add Font Awesome to Nuxt 3!
 */ 

// ===
// STEP 1: Install @fortawesome/vue-fontawesome@latest-3 with npm or yarn
// ===

// npm i --save @fortawesome/vue-fontawesome@latest-3 @fortawesome/fontawesome-svg-core @fortawesome/vue-fontawesome
// yarn add @fortawesome/vue-fontawesome@latest-3 @fortawesome/fontawesome-svg-core @fortawesome/vue-fontawesome

// ===
// STEP 2: Create a `plugins/fontawesome.js` file and copy paste this
// ===
import { library, config } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { fas } from '@fortawesome/free-solid-svg-icons'
import { fab } from '@fortawesome/free-brand-svg-icons'

// This is important, we are going to let Nuxt worry about the CSS
config.autoAddCss = false

// You can add your icons directly in this plugin. See other examples for how you
// can add other styles or just individual icons.
library.add(fas)
library.add(fab)

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.component('font-awesome-icon', FontAwesomeIcon, {})
})

// ===
// STEP 3: Add the Font Awesome CSS to your Nuxt config
// Note: you don't have to specify plugin as you would previously in Nuxt 2.
// ===

// nuxt.config.ts
export default defineNuxtConfig({
  // ...
  css: [
    '@fortawesome/fontawesome-svg-core/styles.css'
  ]
  // ...
})

// And that's pretty much it! You can use use FA to your Nuxt 3 project!
Source by fontawesome.com #
 
PREVIOUS NEXT
Tagged: #nuxt #font #awesome
ADD COMMENT
Topic
Name
5+9 =