Package Data | |
---|---|
Maintainer Username: | chrispage1 |
Maintainer Contact: | chris@motocom.co.uk (Chris Page) |
Package Create Date: | 2022-07-10 |
Package Last Update: | 2024-10-17 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-30 15:12:08 |
Package Statistics | |
---|---|
Total Downloads: | 455,761 |
Monthly Downloads: | 10,352 |
Daily Downloads: | 307 |
Total Stars: | 28 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
vite()
helper methodA super simple Laravel helper to fill the void that Laravel Mix left. Mix had a helper, aptly named mix()
that would return an absolute URL to the mix resource. With the introduction of Vite (as of Laravel 9.19),
there is no equivalent for Vite, at least, until now.
This was originally submitted as a PR to the core Laravel framework, but unfortunately wasn't deemed as a necessary addition.
You can install the package via composer:
composer require motomedialab/laravel-vite-helper
The usage for this helper is extremely simple, and directly replaces Laravel's mix()
helper.
// will return the absolute compiled asset path for 'resources/css/app.css'
vite('resources/css/app.css');
// will return the absolute compiled asset path for
// 'resources/css/app.css' with custom build directory 'dist'
vite('resources/css/app.css', 'dist');
// the third argument enforces a relative path to be returned
vite('resources/css/app.css', 'build', true);
Using this helper may cause some tests that directly interact with your web pages to break if you don't have the compiled assets available (e.g. in a CI/CD flow).
To overcome this, there's a MocksViteHelper
trait that can be used within your tests:
class ExampleTest extends TestCase
{
use MocksViteHelper;
public function a_request_to_a_view_using_vite_helper()
{
$this->withoutViteHelper();
$response = $this->get('/');
$response->assertStatus(200);
}
public function restore_vite_helper_functionality()
{
$this->withViteHelper();
$response = $this->get('/');
$response->assertStatus(500);
}
}
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email chris@motocom.co.uk instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.