Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Font Awesome Laravel Package

components/font-awesome

Shim repository for Font Awesome, providing the icon font, CSS/LESS/SASS, and webfonts via common package managers (Composer, npm, Bower, Component). Use it to include Font Awesome assets in your build pipeline and projects.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Install via Composer:

    composer require components/font-awesome
    

    This installs the package in vendor/components/font-awesome.

  2. Set Up Asset Pipeline:

    • For Laravel Mix (Webpack): Ensure your webpack.mix.js includes Font Awesome’s SASS files:

      mix.sass('resources/scss/app.scss', 'public/css')
          .options({
              processCssUrls: false,
              postCss: [require('postcss-import')()]
          });
      

      Then import Font Awesome in resources/scss/app.scss:

      @import '~@fortawesome/fontawesome-free/scss/fontawesome';
      @import '~@fortawesome/fontawesome-free/scss/solid';
      @import '~@fortawesome/fontawesome-free/scss/regular';
      @import '~@fortawesome/fontawesome-free/scss/brands';
      
    • For Vite: Update vite.config.js:

      import { defineConfig } from 'vite';
      import laravel from 'laravel-vite-plugin';
      
      export default defineConfig({
          plugins: [
              laravel({
                  input: ['resources/scss/app.scss'],
                  refresh: true,
              }),
          ],
      });
      

      Import Font Awesome in resources/scss/app.scss (same as above).

  3. Move Font Files: Copy the font files to your public directory for direct access:

    mkdir -p public/fonts/fontawesome
    cp -r vendor/components/font-awesome/webfonts/* public/fonts/fontawesome/
    

    Update your CSS to reference the local fonts:

    @font-face {
        font-family: 'Font Awesome 6 Free';
        src: url('../fonts/fontawesome/fa-solid-900.woff2') format('woff2'),
             url('../fonts/fontawesome/fa-solid-900.woff') format('woff');
        font-weight: 900;
        font-style: normal;
    }
    
  4. First Usage: Use icons in Blade templates:

    <i class="fas fa-user"></i> <!-- Solid icon -->
    <i class="far fa-envelope"></i> <!-- Regular icon -->
    <i class="fab fa-twitter"></i> <!-- Brand icon -->
    

Implementation Patterns

Usage Patterns

  1. Blade Templates:

    • Static Icons:
      <button class="p-2">
          <i class="fas fa-search"></i>
      </button>
      
    • Dynamic Icons with Helpers: Create a helper to generate icons dynamically:
      // app/Helpers/IconHelper.php
      namespace App\Helpers;
      class IconHelper {
          public static function render(string $icon, string $style = 'solid', string $prefix = 'fa'): string {
              return "<i class=\"{$prefix}{$style} fa-{$icon}\"></i>";
          }
      }
      
      Usage in Blade:
      {{ App\Helpers\IconHelper::render('user', 'solid') }}
      
  2. Tailwind CSS Integration: Combine Font Awesome with Tailwind utility classes for responsive and interactive icons:

    <i class="fas fa-spinner fa-spin text-blue-500"></i>
    <i class="fas fa-check-circle text-green-500 hover:text-green-700"></i>
    
  3. Livewire/Alpine.js: Use icons for dynamic states:

    <!-- Livewire example -->
    <button wire:click="toggle" class="p-2">
        <i class="fas fa-{{ $isActive ? 'check' : 'times' }}"></i>
    </button>
    
    <!-- Alpine.js example -->
    <div x-data="{ open: false }">
        <button @click="open = !open" class="p-2">
            <i :class="open ? 'fas fa-times' : 'fas fa-bars'"></i>
        </button>
    </div>
    
  4. SVG Icons (Advanced): For better performance or customization, use SVG icons via a plugin like vite-plugin-svg-icons:

    // vite.config.js
    import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
    import path from 'path';
    
    export default defineConfig({
        plugins: [
            createSvgIconsPlugin({
                iconDirs: [path.resolve(process.cwd(), 'resources/icons')],
                symbolId: 'icon-[dir]-[name]',
            }),
        ],
    });
    

    Then reference SVG icons in your templates:

    <svg class="w-6 h-6 text-blue-500">
        <use href="#icon-user" />
    </svg>
    

Workflows

  1. Icon Selection:

  2. Theming: Customize icon colors and styles via CSS:

    .text-primary {
        color: #3b82f6; // Tailwind blue-500
    }
    .fa-icon {
        @apply text-primary;
    }
    
  3. Lazy Loading: Load icons dynamically to improve performance:

    <div class="icon-container">
        <i class="fas fa-user lazy-icon" data-icon="user"></i>
    </div>
    
    <script>
        document.querySelectorAll('.lazy-icon').forEach(icon => {
            const style = document.createElement('style');
            style.textContent = `
                @import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css');
            `;
            document.head.appendChild(style);
        });
    </script>
    
  4. Accessibility: Ensure icons are accessible by adding ARIA labels or screen reader-only text:

    <i class="fas fa-search" aria-hidden="true"></i>
    <span class="sr-only">Search</span>
    

Integration Tips

  1. Laravel Mix/Vite:

    • Use purgecss or unplugin-icons to remove unused icon styles from your CSS bundle.
    • Example for unplugin-icons:
      // vite.config.js
      import Icons from 'unplugin-icons/vite';
      import { FileSystemIconLoader } from 'unplugin-icons/loaders';
      
      export default defineConfig({
          plugins: [
              Icons({
                  compiler: 'vue',
                  customLoader: FileSystemIconLoader('./resources/icons'),
              }),
          ],
      });
      
  2. CDN Fallback: For faster loading, use a CDN and cache it:

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="..." crossorigin="anonymous">
    
  3. Versioning:

    • Pin the version in composer.json to avoid unexpected updates:
      "components/font-awesome": "^6.4.0"
      
    • For critical projects, consider forking the repository to control updates.
  4. Testing:

    • Test icons across browsers, especially Safari for font-face issues.
    • Use tools like Lighthouse to audit icon performance and accessibility.

Gotchas and Tips

Pitfalls

  1. Font Loading Issues:

    • Problem: Icons may not render if the font files are not correctly referenced or loaded.
    • Solution: Ensure the font files are copied to the public directory and the CSS @font-face rules point to the correct paths. Test in incognito mode to rule out caching issues.
  2. Breaking Changes in v6.x:

    • Problem: Font Awesome v6.x introduced changes like renaming fa- to fa-solid, fa-regular, etc., which can break existing code.
    • Solution: Audit your Blade templates and CSS for deprecated classes. Use the Font Awesome migration guide for details.
  3. Asset Pipeline Conflicts:

    • Problem: Mixing Font Awesome with other icon libraries (e.g., Heroicons) can lead to CSS conflicts or duplicate font loads.
    • Solution: Use unique class names or namespaces for each icon library. For example:
      <!-- Font Awesome -->
      <i class="fas fa-user"></i>
      
      <!-- Heroicons -->
      <svg class="h-6 w-6 text-gray-800" fill="none" viewBox="0 0 24 24" stroke="currentColor">
          <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h1
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/privacy-filter-classifier
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi