What's going on here? The findIconDefinition() method is using the library to locate an icon that matches the prefix and iconName.
The Library enables all icon lookups
Without the Library any method of the API that needs to locate an icon would be unable to find it. The Library is a required piece of the puzzle and it's a good idea to become familiar with it if you are going to use the API.
The glasses object contains all the information about the icon–size, prefix, name, and the SVG path data. This is known as the icon definition.
One of the most useful API methods to use icon definitions with is icon(). It can transform an icon definition into an SVG representation suitable for use in the DOM or elsewhere.
import{ findIconDefinition, icon }from'@fortawesome/fontawesome-svg-core'const glasses =findIconDefinition({prefix:'fas',iconName:'glasses'})const i =icon(glasses)// Loop through each node and appending it to the DOM body
Array.from(i.node).map(n=> document.body.appendChild(n))
Advertisement
Remove ads with a Pro plan!
Using this requires Font Awesome Pro
Pro
A subscription to a Pro-level plan will remove all third-party advertisments on fontawesome.com.
And of course Pro-level plans come with…
All 16,150 Icons in Font Awesome
Solid, Regular, Light, Thin, and Duotone Styles for Each Icon + Brands
A Perpetual License to Use Pro
Services and Tools to Make Easy Work of Using Icons
While it's easy to add entire styles to the library this results in some big
files. A typical site, even one that uses a lot of icons, will only need a
small portion of the thousands of icons Font Awesome provides.
That's where subsetting comes in.
Let's take our previous example and only import the icons that we need.
You can reap the benefits of this explicit import through bundling tools that
eliminate "dead code". Dead code is anything in your final bundle that will
never be used by your project (making it safe to be removed). This process is
known as tree shaking. Rollup(opens new window) and Webpack 2+(opens new window) are a couple of tools that support tree shaking(opens new window).