Nuxt module for Fontawesome 5 integration with ES6 imports and tree shaking
Switch branches/tags
Nothing to show
Clone or download
Latest commit 715786f Jun 28, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Updated to work with fontawesome 5.1 Jun 28, 2018
.eslintrc.js Initial commit Feb 10, 2018
.gitignore Initial commit Feb 10, 2018
CHANGELOG.md Updated to work with fontawesome 5.1 Jun 28, 2018
LICENSE Initial commit Feb 10, 2018
README.md Updated to work with fontawesome 5.1 Jun 28, 2018
package-lock.json 0.3.0 Jun 28, 2018
package.json 0.3.0 Jun 28, 2018

README.md

Nuxt Font Awesome 5

npm (scoped with tag) npm

Plugin to join nuxt and Font Awesome 5 icons using official vue-fontawesome plugin. Supports ES6 imports with tree shaking and fix of initial load flickering

0.2 to 0.3 upgrade

Updated due to release of fontawesome 5.1 with some breaking changes. Please refer to vue-fontawesome UPGRADING guide and use current version of README docs

General differences:

  • Fontawesome now has no default imports, you have to specify icons: ['fas'] to import whole set.
  • Packages changed. You'll need to update your package.json file with the renamed packages and new versions.
  • Improved tree shaking support, no need to setup it with build and shakable.es.js', so remove this block

Setup

  • Add dependencies using npm to your project
    npm i nuxt-fontawesome
    Also it may be needed to explicitly install fontawesome, if your webpack build fails
    npm i @fortawesome/fontawesome-svg-core @fortawesome/vue-fontawesome

  • Configure nuxt.config.js:

    • Add nuxt-fontawesome to modules section
    • Configure loaded icons/whole sets
  • See more details about usage below

{
  modules: [
    'nuxt-fontawesome',
    //OR like this
    ['nuxt-fontawesome', {
      component: 'fa', 
      imports: [
        //import whole set
        {
          set: '@fortawesome/free-solid-svg-icons',
          icons: ['fas']
        },
        //import 2 icons from set 
        // please note this is PRO set in this example, 
        // you must have it in your node_modules to actually import
        {
          set: '@fortawesome/pro-regular-svg-icons',
          icons: ['faAdjust', 'faArchive']
        }
      ]
    }]
  ],
  //alternative place for config
  fontawesome: {
    imports: [
      ...
    ]
  }
}

Module options

component

Change component name. For example, fa to use like <fa ... />

  • Default: font-awesome-icon

imports

Import icons/whole sets from chosen packages

  • Default: [], no icons will be imported here (see below, can be loaded later inside .vue file)
    • set - path to node package for import, like @fortawesome/free-solid-svg-icons
    • icons - array of icons to import ['faAdjust', 'faArchive'].

Usage

Please see vue-fontawesome for additional reference

  • Add needed dependency, like
    npm i @fortawesome/free-solid-svg-icons
  • Add configuration like this in nuxt.config.js
{
  fontawesome: {
    imports: [
        {
          set: '@fortawesome/pro-regular-svg-icons',
          icons: ['faAdjust']
        },
        {
          set: '@fortawesome/free-solid-svg-icons',
          icons: ['fas']
        },
    ],
  },
}

Then use

<template>
    <div>
        <font-awesome-icon :icon="['fas', 'adjust']"  />
        <font-awesome-icon icon="dollar-sign"  style="font-size: 30px"/>
    </div>
</template>
  • Load and use directly in template. Component name changed in nuxt.config.js to fa
fontawesome: {
  component: 'fa'
},
<template>
    <div>
        <fa :icon="fas.faAddressBook"  />
        <fa :icon="faGithub" />
    </div>
</template>
<script>
  import { fas } from '@fortawesome/free-solid-svg-icons'
  import { faGithub } from '@fortawesome/free-brands-svg-icons'
  export default {
    computed: {
      fas () {
         return fas
      },
      faGithub () {
         return faGithub
      }
    },
  }
  </script>

License

MIT, made by Galley Web Development