Laravel and Vite: Fixing Manifest Issues After Upgrade

Introduction

After upgrading to Vite 6 in a Laravel project, you might encounter issues with the location of the manifest.json file. The laravel-vite-plugin version 0.8 expects the manifest in build/manifest.json, but Vite 6 outputs it to .vite/manifest.json. This discrepancy can break asset loading in your application.

The Problem: Manifest File Location

When upgrading to newer versions of Vite, the default output directory for the manifest file may change. This is a common issue and requires a configuration adjustment to ensure that Laravel can correctly locate the manifest.

The Solution: build.manifest Configuration

To resolve this, you can configure Vite to output the manifest file to the location expected by laravel-vite-plugin v0.8. Add the build.manifest option to your vite.config.js file:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
    ],
    build: {
        manifest: true,
        outDir: 'public/build',
    },
});

This configuration explicitly tells Vite to generate the manifest file. By setting the build.outDir option, you also define where the generated assets will be located.

Why This Works

The laravel-vite-plugin relies on the manifest file to map your application's assets to their respective URLs. By ensuring that the manifest is in the expected location, you prevent broken asset paths and ensure that your application loads correctly.

Results

By adding the build.manifest configuration, you ensure compatibility between Vite 6 and older versions of laravel-vite-plugin, allowing your assets to load correctly after the upgrade. This approach provides a temporary solution until the plugin is upgraded to v1.x, which natively supports the new manifest location.

Next Steps

As a next step, consider upgrading laravel-vite-plugin to the latest version (v1.x or later) to take advantage of native support for Vite 6's manifest location and other improvements. Staying up-to-date with the latest versions of your dependencies is crucial for long-term maintainability and access to new features and bug fixes.

Laravel and Vite: Fixing Manifest Issues After Upgrade
GERARDO RUIZ

GERARDO RUIZ

Author

Share: