honda / pushed-resources
动态添加样式或脚本
1.1.0
2021-05-14 11:02 UTC
Requires
- php: ^8
- felixdorn/laravel-render-blade-string: ^1.0
- illuminate/contracts: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- gajus/dindent: ^2.0
- orchestra/testbench: ^6.17
- pestphp/pest: ^1.0.5
- phpstan/phpstan: ^0.12.48
- symfony/var-dumper: ^5.2.0
This package is auto-updated.
Last update: 2024-09-10 02:46:43 UTC
README
安装
您可以通过composer安装此包
composer require honda/pushed-resources
用法
推送资源
使用Blade
<x-assets-script async src="script.js"/> <x-assets-raw-script> console.log('Hello there!') </x-assets-raw-script> <x-assets-style href=" style.css"/> <x-assets-raw-style> * { background: rebeccapurple } </x-assets-raw-style> <x-assets-blade> @livewireStyles @livewireScripts </x-assets-blade>
使用PHP
use Honda\PushedResources\Resources\Script; use Illuminate\View\ComponentAttributeBag; Script::create() ->value('something.js') ->attributes(['a' => 'b']) // or ->attributes(new ComponentAttributeBag(['a' => 'b']));
检索资源
使用Blade
<x-assets-render type="*"/> <x-assets-render type="script"/> <x-assets-render type="script,raw-script"/> <x-assets-render type="style,raw-style"/> <x-assets-render type="style,raw-style"/>
使用PHP
use Honda\PushedResources\Resources\Script; use Illuminate\View\ComponentAttributeBag; Script::create() ->value('something.js') ->attributes(['a' => 'b']) // or ->attributes(new ComponentAttributeBag(['a' => 'b']));
您也可以在同一命名空间中使用
Style
、Script
、RawScript
、RawStyle
、Blade
自定义类型
一个很好的用例是Livewire资源,你可能不希望在未使用Livewire的页面上使用这些资源。你可以这样做
// app/View/Resources/BladeScript or wherever you think it makes sense. class BladeScript extends \Honda\PushedResources\Resources\Blade { public function getTag() : string{ return 'blade-script'; } }
// app/View/Components/BladeScript.php class BladeScript extends \Honda\PushedResources\Components\Blade {}
// in a page with livewire <x-blade-script> <livewire-scripts/> </x-blade-script> // at the bottom of <body> in your layout file <x-assets-render type="blade-script"/>
测试
composer test
Octane
此包与Laravel Octane兼容。
鸣谢
许可证
MIT许可证(MIT)。请参阅许可证文件获取更多信息。