Blog Detail

04

Aug
Helper Method to Generate Absolute Asset URLs to Vite Assets cover image

arrow_back Helper Method to Generate Absolute Asset URLs to Vite Assets

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 mixed 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 this package via composer by running this command:

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 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);

For more details and source code, Visit Github

Note

The expert team of Laravel developers at Codebrisk is always ready to execute even your boldest ideas. Our expert team can design and develop any type of custom CRM solution, SAAS app, or e-commerce app to meet our customer’s needs and transform our customer’s experiences. Get in touch with our team to discuss your bespoke ideas and learn more about the next steps to launching cooperation.

Published at : 04-08-2022

Author : Rizwan Aslam
AUTHOR
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project