Install via Composer (if not archived, verify compatibility with your Laravel version):
composer require c975l/includelibrary-bundle
Note: Since the bundle is archived, ensure no breaking changes exist in your Laravel version (e.g., Symfony 4+ compatibility).
Register the Bundle (Laravel 5.x/6.x):
Add to config/app.php under providers:
C975L\IncludeLibraryBundle\IncludeLibraryBundle::class,
Publish Config (if needed):
php artisan vendor:publish --provider="C975L\IncludeLibraryBundle\IncludeLibraryBundle" --tag=config
Check config/include_library.php for default settings (e.g., CDN paths, fallbacks).
First Use Case:
Replace hardcoded CDN links in a Blade template (e.g., resources/views/layouts/app.blade.php):
{{ inc_lib('bootstrap', 'css', '4.6.0') }}
{{ inc_lib('bootstrap', 'js', '4.6.0') }}
{{ inc_lib('google-font', 'family', 'Roboto:400,700') }}
Library Inclusion:
{{ inc_lib('library', 'type', 'version') }}
library: bootstrap, jquery, font-awesome, etc. (see supported libraries).type: css, js, or family (for Google Fonts).version: Specific version (e.g., 3.3.7) or wildcard * (uses latest).<!-- jQuery + Popper.js (Bootstrap 4 dependency) -->
{{ inc_lib('jquery', 'js', '3.5.1') }}
{{ inc_lib('popper', 'js', '1.16.1') }}
{{ inc_lib('bootstrap', 'css', '4.6.0') }}
Google Fonts:
family type with comma-separated font strings:
{{ inc_lib('google-font', 'family', 'Open+Sans:400,700|Roboto:italic,500') }}
Local Fallbacks:
config/include_library.php to use local copies if CDN fails:
'fallback_paths' => [
'bootstrap' => 'vendor/bootstrap/dist/',
],
Dynamic Versioning:
'versions' => [
'bootstrap' => '4.6.0', // Override default
],
Asset Optimization:
Combine with Laravel Mix/Webpack to bundle JS/CSS locally for production.
Example: Exclude inc_lib outputs from Mix processing by using unique class names:
{{ inc_lib('bootstrap', 'css', '4.6.0', ['class' => 'no-mix-process']) }}
Twig Compatibility:
If using Twig, register the helper in app/Twig/Extensions/IncludeLibraryExtension.php:
public function getFunctions()
{
return [
new \Twig\TwigFunction('inc_lib', [$this, 'includeLibrary']),
];
}
Environment-Specific Libraries: Use Blade directives to conditionally load libraries:
@if(config('app.env') === 'production')
{{ inc_lib('bootstrap', 'css', '4.6.0') }}
@else
{{ inc_lib('bootstrap', 'css', '*') }} <!-- Latest for dev -->
@endif
Archived Status:
SRI (Subresource Integrity) Issues:
Failed to find a valid digest errors. Override hashes in config:
'sri_overrides' => [
'bootstrap' => [
'css' => 'sha384-...', // Manually add correct hash
],
],
Version Wildcards (*):
config/include_library.php for critical projects.Google Fonts Caching:
family string exceeds URL length limits (~2000 chars).inc_lib calls or use a subset of weights/styles.Laravel Mix Conflicts:
inc_lib outputs don’t interfere with asset hashing. Use unique filenames:
// config/include_library.php
'asset_options' => [
'bootstrap_css' => ['attributes' => ['id' => 'bootstrap-css']],
],
Check Loaded Libraries:
Enable debug mode in config/include_library.php:
'debug' => true,
Outputs a list of included libraries to the footer.
Verify CDN Availability:
Test CDN URLs manually (e.g., https://maxcdn.bootstrapcdn.com/bootstrap/4.6.0/css/bootstrap.min.css) before blaming the bundle.
Clear Config Cache:
After modifying config/include_library.php, run:
php artisan config:clear
Add Custom Libraries: Extend the bundle by creating a service provider to register new libraries:
// app/Providers/IncludeLibraryServiceProvider.php
use C975L\IncludeLibraryBundle\Manager\LibraryManager;
public function register()
{
$this->app->make(LibraryManager::class)->addLibrary([
'name' => 'custom-lib',
'css' => 'https://cdn.example.com/{version}/custom.css',
'js' => 'https://cdn.example.com/{version}/custom.js',
]);
}
Override Default Templates: Publish and modify the Blade template:
php artisan vendor:publish --provider="C975L\IncludeLibraryBundle\IncludeLibraryBundle" --tag=views
Edit resources/views/vendor/includelibrary/default.blade.php to customize output (e.g., add defer to scripts).
Custom Attributes: Pass additional HTML attributes via the 4th parameter:
{{ inc_lib('bootstrap', 'js', '4.6.0', ['defer' => 'defer', 'data-turbolinks-eval' => 'false']) }}
Local Development Proxy: Use Laravel Valet/Vagrant to mirror CDN files locally for offline testing:
// config/include_library.php
'cdn_proxies' => [
'bootstrap' => 'http://localhost:8000/vendor/bootstrap/',
],
How can I help you explore Laravel packages today?