Last active
October 10, 2025 09:07
-
-
Save lrtrln/405ccf523e4376d20c9598e38dfc0854 to your computer and use it in GitHub Desktop.
Agnostic Vite config for Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { defineConfig } from 'vite'; | |
| import laravel, { refreshPaths } from 'laravel-vite-plugin'; | |
| import dotenv from 'dotenv'; | |
| import fs from 'fs'; | |
| dotenv.config(); | |
| const port = 5173; | |
| const appUrl = process.env.APP_URL || 'http://localhost'; | |
| const { protocol, hostname } = new URL(appUrl); | |
| // helper → vérifie qu'un fichier existe avant de l'ajouter aux entrées | |
| const safeInput = (paths) => | |
| paths.filter((path) => fs.existsSync(path)); | |
| export default defineConfig({ | |
| plugins: [ | |
| laravel({ | |
| input: safeInput([ | |
| 'resources/css/app.css', | |
| 'resources/js/app.js', | |
| 'resources/scss/bootstrap.scss', // ignoré si inexistant | |
| 'resources/js/bootstrap.js', | |
| ]), | |
| refresh: [ | |
| ...refreshPaths, | |
| 'app/Http/Livewire/**', | |
| 'app/Filament/**', | |
| 'resources/views/**/*.blade.php', | |
| ], | |
| }), | |
| // Recharge Blade sans bug sur les templates | |
| { | |
| name: 'blade', | |
| handleHotUpdate({ file, server }) { | |
| if (file.endsWith('.blade.php')) { | |
| server.ws.send({ type: 'full-reload', path: '*' }); | |
| } | |
| }, | |
| }, | |
| ], | |
| server: { | |
| watch: { | |
| // Ignore heavy or useless directories | |
| ignored: [ | |
| '**/vendor/**', | |
| '**/storage/**', | |
| '**/node_modules/**', | |
| '**/public/**', | |
| '**/bootstrap/cache/**', | |
| ], | |
| }, | |
| host: hostname || 'localhost', | |
| port, | |
| strictPort: true, | |
| https: protocol === 'https:', | |
| cors: true, | |
| origin: `${protocol}//${hostname}:${port}`, | |
| hmr: { | |
| host: hostname, | |
| protocol: protocol === 'https:' ? 'wss' : 'ws', | |
| }, | |
| }, | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment