simtabi/laravel-assets

A highly opinionated assets management library for the Laravel framework.

dev-master 2022-11-30 22:58 UTC

This package is auto-updated.

Last update: 2023-01-30 23:36:06 UTC


README

banner

Laravel Assets management

A highly opinionated assets management library for the Laravel framework.

Requirements

To be able to use this package you need to meet the following minimum requirements:

  1. Laravel framework >= v9
  2. PHP >= v8

Installation

composer require simtabi/laravel-assets

For version <= 5.4:

Add to section providers of config/app.php:

// config/app.php
'providers' => [
    ...
    Simtabi\Assets\Providers\AssetsServiceProvider::class,
];

And add to the aliases section:

// config/app.php
'aliases' => [
    ...
    'Assets' => Simtabi\Assets\Facades\AssetsFacade::class,
];

All assets resource will be manage in config file, so we need to publish config to use.

php artisan vendor:publish --provider="Simtabi\Assets\Providers\AssetsServiceProvider" --tag=config

Add to your master layout view, in head tag:

{!! \Assets::renderHeader() !!}

and before body tag close:

{!! \Assets::renderFooter() !!}

Methods

Add scripts

\Assets::addScripts(['key-of-assets-in-config-file']);

Example:

\Assets::addScripts(['app', 'bootstrap', 'jquery']);

Add styles

\Assets::addStyles(['key-of-assets-in-config-file']);

Example:

\Assets::addStyles(['bootstrap', 'font-awesome']);

Remove scripts

\Assets::removeScripts(['key-of-assets-in-config-file']);

Example:

\Assets::removeScripts(['bootstrap']);

Remove styles

\Assets::removeStyles(['key-of-assets-in-config-file']);

Example:

\Assets::removeStyles(['font-awesome']);

Others

  • Set version for assets. Add to .env
ASSETS_VERSION=1.0

Then all assets will be added ?v=1.0

  • Change to online mode
ASSETS_OFFLINE=false

Then assets will be loaded from CDN if it's defined in config file.

  • To disable versioning:
ASSETS_ENABLE_VERSION=false

Contributors

License

MIT © Simtabi LLC