Search code examples
laravel-8vitelaravel-9

How to use vite with Laravel to minify css and js


I am using an HTML template with Laravel and for every page write my custom js and CSS for features.

I want to use vitejs to minify all my js and CSS files

Like any changes in the js file (filename.js) in the project-root/resources/js directory

vitejs work in the background and update the file (filename.min.js) in the project-root/public/js directory

and same for css

reference:

https://vitejs.dev/config/build-options.html#build-minify


Solution

  • Take a look at

    https://laravel.com/docs/9.x/vite

    Once you have it setup you

    npm run dev

    to get updated css/js files during development

    and npm run build to generate minified files to deploy