A helper method to generate absolute asset URL's to Vite assets

Overview

Laravel vite() helper method

Latest Version on Packagist Total Downloads GitHub Actions

A 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.

Installation

You can install the package via composer:

composer require motomedialab/laravel-vite-helper

Usage

The usage for this helper is extremely simple, and directly replaces Laravel's mix() helper.

// will return the compiled asset path for 'resources/css/app.css'
vite('resources/css/app.css');

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

You might also like...
Template for repository helper, library - Basic, Simple and Lightweight

Template start helper, library Template for repository helper, library - Basic, Simple and Lightweight Use this Template First, you can Use this templ

This package provides an artisan command to generate a basic crud with Restful API support

NHRROB Crud Generator Package This package provides an artisan command to generate a basic crud composer install command: composer require nhrrob/crud

Generate dummy API endpoints from a simple PHP array.

Laravel Fake API Create placeholder API endpoints from a simple PHP array. LFA utilizes Faker for dummy data. Inspired by JSON Server. Installation To

A prototype generator to quickly generate prototypes based on Neos nodetype definitions.
A prototype generator to quickly generate prototypes based on Neos nodetype definitions.

UpAssist.PrototypeGenerator What does this package do? This package lets you create scaffolding for prototypes for Neos using the commandline. Why did

Generate Admin Panels CRUDs and APIs in Minutes with tons of other features and customizations with 3 different themes
Generate Admin Panels CRUDs and APIs in Minutes with tons of other features and customizations with 3 different themes

InfyOm Laravel Generator Generate Admin Panels CRUDs and APIs in Minutes with tons of other features and customizations with 3 different themes. Docum

Asset Component is a port of Laravel 3 Asset for Orchestra Platform.

Asset Component is a port of Laravel 3 Asset for Orchestra Platform. The component main functionality is to allow asset declaration to be handle dynamically and asset dependencies can be resolve directly from the container. It however is not intended to becoma an asset pipeline package for Laravel, for such purpose we would recommend to use Grunt or Gulp.

The Asset component manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files.

Asset Component The Asset component manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files. Res

Plugin Vite is the conduit between Craft CMS plugins and Vite, with manifest.json & HMR support

Plugin Vite Related Articles: Vite.js Next Generation Frontend Tooling + Craft CMS A Vite Buildchain for Craft CMS Plugins Requirements Craft CMS 3.0.

Plugin for Kirby that allows you to load assets generated by Vite.

Kirby Vite Plugin Plugin for Kirby that allows you to load assets generated by Vite. In development mode, assets are loaded from Vite's development se

Assets Manager for
Assets Manager for "Vitewind" Theme, will inject CSS and JS assets for "Vitewind" theme to work properly with viteJS in development and production

Vitewind Manager plugin 💨 Windi CSS and ⚡️ Vite, for 🍂 OctoberCMS & ❄️ WinterCMS Introduction This is a helper plugin for 💨 Vitewind theme, don't i

Pimcore Localized Assets - localize your assets with no duplicating files
Pimcore Localized Assets - localize your assets with no duplicating files

Localized assets in Pimcore Pimcore Bundle to localize your assets with same file. Installation composer require lemonmind/pimcore-localized-assets bi

Enable method chaining or fluent expressions for any value and method.

PHP Pipe Operator A (hopefully) temporary solution to implement the pipe operator in PHP. Table of contents Requirements How to install How to use The

Laravel-Mix helper for projects with complex & multi assets.
Laravel-Mix helper for projects with complex & multi assets.

Laravel-Mix helper for projects with complex & multi assets. 🔥 Getting started Since mix introduced in laravel 5.4 it is recommended to use this pack

`dd` is a helper method in Laravel. This package will add the `dd` to your application.

dd dd is a helper method in Laravel. This package will add the dd to your application. Install Run composer require larapack/dd 1.* For Laravel Larave

Generate Laravel route URLs from JavaScript.
Generate Laravel route URLs from JavaScript.

Laroute Laravel has some pretty sweet helper functions for generating urls/links and its auto-json-magic makes it building APIs super easy. It's my go

Easily generate URLs to Minecraft avatars with the ability to switch between services

Minecraft Avatar URLs This library provides PHP utilities to generate URLs to Minecraft Avatars in different formats with the ability to easily change

A helper package to flash a bootstrap alert to the browser via a Facade or a helper function.

Alert Box (Laravel) A helper package to flash a bootstrap alert to the browser via a Facade or a helper function. div class="alert alert-info fade in

Cache-purge-helper - Additional instances where nginx-helper and lscache plugin should be purged.

cache-purge-helper Additional instances where nginx-helper and lscache plugin should be purged. Install Extract the zip file. Upload them to /wp-conte

Comments
  • Respect `withoutVite`

    Respect `withoutVite`

    Hello!

    Thank you for making this helper. I ran into some troubles when testing and wanted to suggest a feature (that I'm not smart enough to implement).

    Background

    We have some tests that assert that views are rendered, or at least contain certain HTML code. Before we used $this->withoutMix() in our test setup and this seemed to make sure that the mix() directive ran safely.

    There is a $this->withoutVite equivalent, but I've had to mock the vite helper myself.

    Desired change

    It would be really cool if the vite() helper could somehow detect that $this-withoutVite() is active and return a dummy path on all calls to it, or just the path to the unbuilt resource.

    Below you'll find the mock that I used to solve the problem for now:

    $viteHelperMock = $this->mock(LaravelViteHelper::class, function (MockInterface $mock) {
        $mock->shouldReceive('resourceUrl')->andReturn('/some-path');
    });
    
    $this->app->instance('vite', $viteHelperMock);
    
    enhancement 
    opened by vilbergs 3
Owner
MotoMediaLab
MotoMediaLab Limited is a creative digital agency creating bespoke solutions.
 MotoMediaLab
Laravel Starter With Laravel, Vite, Vue 2, Inertia.js, Ziggy

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Oskars Germovs 1 Oct 29, 2021
Laravel Starter With Laravel, Vite, Vue 2, Inertia.js, Ziggy, Typescript

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Oskars Germovs 1 Oct 29, 2021
A starter template from which to build Laravel + Vite apps

Stack The Laravel framework is fast, clean, and filled with best practices. In this stack, it will handle the backend as an API. The Laravel Vite pack

null 7 Nov 14, 2022
A Laravel 9, Vite, Svelte SPA, Tailwind CSS (w/ Forms Plugin & Aspect Ratio Plugin), Axios & TypeScript starter template.

Laravel 9 + Vite + Svelte + Tailwind CSS This starter template includes: Laravel 9 Vite Svelte Tailwind CSS (w/ @tailwindcss/forms and @tailwindcss/as

Ronnie 19 Dec 20, 2022
Starter - Laravel, Vue, Inertia, Tailwind, Vite

Starter - Laravel, Vue, Inertia, Tailwind, Vite Laravel-vite preset Laravel 9 Vue 3 Inertia Tailwind Vite Including Sail (Docker). php 8.1 mysql 8.0 p

Anatoliy 6 Dec 28, 2022
React laravel starter kit with tailwind css and vite js(laravel 9)

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Jerald Tonmoy Dias 2 Dec 23, 2022
compile multiple tailwind.config.js with laravel-vite plugin

Compile multiple tailwind css from different tailwind.config.js files using laravel-vite If do you want to compile two or more tailwind css from diffe

Muhammad Amir 15 Dec 19, 2022
Repositorio del tutorial CRUD Laravel 9 y Vue 3 usando Vite

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Alfredo Morales 2 Sep 29, 2022
A plugin to purge your unused assets, disabled products, and more.

Purge Assets for Craft CMS Purge Assets is a Craft plugin for super-simple purge of assets and products, either via the control panel or with console

Bram Beekman 4 Oct 10, 2021
A modern adoption of a teaching method developed by Helen Parkhurst in the 20th century

Dalton Plan Education with interactive timetable A modern adoption of a teaching method developed by Helen Parkhurst in the 20th century - If you are

Dalton Plan 8 Nov 15, 2022