owenvoke / blade-fontawesome

A package to easily make use of Font Awesome in your Laravel Blade views.
https://packagist.org/packages/owenvoke/blade-fontawesome
MIT License
170 stars 30 forks source link

added config copy only icons #64

Closed 0528Makoto closed 1 year ago

0528Makoto commented 1 year ago

Summary

I am using steam laravel to deploy changes to aws through its steam cli, and this in turn compiles and compresses the project for deployment, what happens is that the project is too heavy due to the blade-fontawesome package copies all the svgs even without these are used

image

My solution

Therefore, I updated the sync of the package so that it only copies the files that I am using in the template

Other posible solution

when deploying list all blade icons in the template and then purge them

ThomasEnssner commented 1 year ago

You could add an option to include all icons of a set in the config, like: 'icons' => '*',

In the sync command you could add:

      // skip if icons are not specified
      if (! isset($item['icons'])) {
          continue;
      }

      // load all files if * is specified
      if ($item['icons'] === '*') {
          $item['icons'] = collect(scandir($assetSourcePath))
              ->filter(fn ($file) => $file !== '.' 
                   && $file !== '..' 
                   && str_ends_with($file, '.svg')
              )
              ->map(fn ($file) => str_replace('.svg', '', $file))
              ->toArray();
      }