Core Laravel Vite plugin configuration and setup options for integrating Vite with Laravel applications.
Creates the main Laravel Vite plugin with optional additional plugins for full page reload functionality.
/**
* Laravel plugin for Vite
* @param config - Configuration object or entry point paths
* @returns Array containing Laravel plugin and optional full reload plugins
*/
export default function laravel(
config: string | string[] | PluginConfig
): [LaravelPlugin, ...Plugin[]];Usage Examples:
import laravel from "laravel-vite-plugin";
// Simple string input
export default defineConfig({
plugins: [laravel("resources/js/app.js")]
});
// Array of inputs
export default defineConfig({
plugins: [laravel([
"resources/css/app.css",
"resources/js/app.js"
])]
});
// Full configuration object
export default defineConfig({
plugins: [laravel({
input: "resources/js/app.js",
publicDirectory: "public",
buildDirectory: "build",
ssr: "resources/js/ssr.js",
refresh: true
})]
});Complete configuration options for the Laravel Vite plugin.
interface PluginConfig {
/** The path or paths of the entry points to compile */
input: Rollup.InputOption;
/** Laravel's public directory (default: 'public') */
publicDirectory?: string;
/** The public subdirectory where compiled assets should be written (default: 'build') */
buildDirectory?: string;
/** The path to the "hot" file (default: `${publicDirectory}/hot`) */
hotFile?: string;
/** The path of the SSR entry point */
ssr?: Rollup.InputOption;
/** The directory where the SSR bundle should be written (default: 'bootstrap/ssr') */
ssrOutputDirectory?: string;
/** Configuration for performing full page refresh on blade file changes (default: false) */
refresh?: boolean | string | string[] | RefreshConfig | RefreshConfig[];
/** Utilise the Herd or Valet TLS certificates (default: null) */
detectTls?: string | boolean | null;
/** @deprecated Use "detectTls" instead. Legacy TLS certificate detection (default: null) */
valetTls?: string | boolean | null;
/** Transform the code while serving */
transformOnServe?: (code: string, url: DevServerUrl) => string;
}Configuration for full page reload functionality when blade templates or other files change.
interface RefreshConfig {
/** Paths to watch for changes */
paths: string[];
/** vite-plugin-full-reload configuration options */
config?: FullReloadConfig;
}
type DevServerUrl = `${'http' | 'https'}://${string}:${number}`;Refresh Configuration Examples:
// Enable default paths
refresh: true
// Single path
refresh: "resources/views/**/*.blade.php"
// Multiple paths
refresh: ["resources/views/**", "routes/**"]
// Full configuration
refresh: {
paths: ["resources/views/**/*.blade.php"],
config: { delay: 300 }
}
// Multiple configurations
refresh: [
{
paths: ["resources/views/**"],
config: { delay: 100 }
},
{
paths: ["routes/**"],
config: { delay: 200 }
}
]Extended Vite plugin interface with Laravel-specific configuration method.
interface LaravelPlugin extends Plugin {
config: (config: UserConfig, env: ConfigEnv) => UserConfig;
}Pre-configured paths that are automatically watched when refresh: true is specified.
/**
* Default paths for full page refresh functionality
* Includes Laravel-specific directories like Livewire components,
* View components, language files, views, and routes
*/
export const refreshPaths: string[];The default paths include:
app/Livewire/** - Livewire componentsapp/View/Components/** - Blade view componentslang/** - Language filesresources/lang/** - Resource language filesresources/views/** - Blade template filesroutes/** - Route definition filesThe plugin performs automatic validation and normalization of configuration options:
input option is provided and not emptypublicDirectory or buildDirectory valuesinput as SSR entry point if ssr is not specifiedThe plugin automatically detects and integrates with various Laravel development environments: