npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@devlop-ab/fontawesome-autoload-webpack-plugin

v1.0.1

Published

Webpack plugin that will search your project and generate an autoload file for only the fontawesome icons you actually use.

Downloads

20

Readme

Font Awesome Autoload

This will search your views and find all Font Awesome Icons you are using and generate an autoload file that you can require in your project. This will help with treeshaking when you are using the Font Awesome Javascript API to manually configure Font Awesome and set up dom.watch, but you still include your icons in your views directly using <i> tags.

Without an autoload file it is impossible for Font Awesome to properly do tree shaking.

Supported Versions

This is made for Font Awesome 6 and has no intentional support for earlier versions.

Installing

using npm

npm install @devlop-ab/fontawesome-autoload-webpack-plugin

Usage

Configure the plugin in your webpack.config.js.

const FontAwesomeAutoloadWebpackPlugin = require('@devlop-ab/fontawesome-autoload-webpack-plugin');

module.exports = {
    plugins: [
        new FontAwesomeAutoloadWebpackPlugin({
            // (REQUIRED) the paths to search 
            paths: [
                path.resolve(__dirname, 'resources/views/**/*.blade.php'),
            ],
            
            // (OPTIONAL) 
            // the path where the autoload file will be saved
            // default is node_modules/.cache/fontawesome-autoload/index.js
            outputPath: path.resolve(__dirname, './node_modules/.cache/fontawesome-autoload/index.js'),
            
            // (OPTIONAL) specify icons to always include in the autoload, must be the fa6 "long prefix" followed by the icon name
            include: [
                // 'fa-brands fa-font-awesome',
                // 'fa-solid fa-elephant',
                // 'fa-regular fa-1','
                // 'fa-light fa-3','
                // 'fa-thin fa-3','
                // 'fa-duotone fa-7','
            ],
            
            // (OPTIONAL)
            // if you want to modify the search logic you can pass your own extractor callback
            // the callback will receive two arguments, file contents and the default extractor
            // and should return an array of found icons, each being an object with prefix and name.
            // optionally you can merge your extractor results with the default extractor results.
            extractor: function (contents, defaultExtractor) {
                // psuedo code example:
                
                let icons = [];
                
                // search the contents ...
                
                // add the icons you find
                icons.push({
                    prefix: 'fa-solid',
                    name: 'fa-rabbit'
                });
                
                // return the icons
                return icons;
                
                // optionally also apply the findings from the defaultExtractor
                return [...icons, ...defaultExtractor(contents)];
            },
            
            // (OPTIONAL) the packages you are using, expects only the package name excluding vendor prefix
            packages: [
                // this is the defaults if not configured
                // 'free-brands-svg-icons',
                // 'pro-duotone-svg-icons',
                // 'pro-light-svg-icons',
                // 'pro-regular-svg-icons',
                // 'pro-solid-svg-icons',
                // 'pro-thin-svg-icons',
            ],
        }),
    ],
}

Require the generated file in your javascript where you configure Font Awesome.

import { library, dom } from '@fortawesome/fontawesome-svg-core';
import icons from '.cache/fontawesome-autoload'; // must match the outputPath

library.add(...icons);
dom.watch();