wambo-co / laravel-mix-twig-extension
Laravel Mix twig 扩展
v1.1.1
2018-11-06 10:00 UTC
Requires
- php: >=7.0
- twig/twig: ~2.0
This package is not auto-updated.
Last update: 2024-09-21 19:20:04 UTC
README
The Laravel mix version
task appends a unique hash to filename, allowing for cache-busting. For example, the generated file name will look something like: all-16d570a7.css
.
In Laravel, you can use in your views the mix()
function to load the appropriately hashed asset
<link rel="stylesheet" href="{{ mix("css/all.css") }}">
This twig extension is an adaptation of this mix()
function.
要求
您需要 PHP >= 7.0 来使用此库,但推荐使用最新稳定的 PHP 版本。
安装
使用 Composer 安装
composer require stormiix/laravel-mix-twig-extension:dev-master
这将编辑(或创建)您的 composer.json 文件并自动选择最新版本。
文档 [待办事项]
注册扩展
use Stormiix\Twig\Extension\MixExtension; $mix = new MixExtension( $publicDir, // the absolute public directory $manifestName // the manifest filename (default value is 'mix-manifest.json') ); $twig->addExtension($mix);
将扩展注册为 Symfony 服务
参考原始仓库。
使用扩展
<link rel="stylesheet" href="{{ Mix('css/all.css') }}"> <script src="{{ Mix('js/all.js') }}"></script>
您可以使用 asset
twig 扩展将其包裹起来,使您的应用程序更便携
<link rel="stylesheet" href="{{ asset(Mix('css/all.css')) }}"> <script src="{{ asset(Mix('js/all.js')) }}"></script>
作者
-
Brieuc Thomas - 初始工作 - Elixir-twig-extension
-
Anas Mazouni - laravel-mix-twig-extension
许可证
本项目采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE.md 文件。