Installation
composer require phppirate/vite-stubby
Run the publisher to publish the stubs:
php artisan vendor:publish --provider="PhpPirate\ViteStubby\ViteStubbyServiceProvider" --tag="vite-stubby"
Configuration
Locate the published config file at config/vite-stubby.php and adjust settings like:
entryPoints (default: ['resources/js/app.js'])buildDirectory (default: public/build)devServerPort (default: 5173)First Use Case
Replace your resources/js/app.js with a basic Vite entry point (e.g., using the published stub):
import './bootstrap';
import '../css/app.css';
Run Vite dev server:
npm run dev
Or build for production:
npm run build
Scaffolding New Projects
Use the published stubs (resources/js/app.js, resources/css/app.css) as a starting point for new Laravel projects, ensuring consistency across teams.
Integration with Laravel Mix
Replace webpack.mix.js with Vite’s vite.config.js (published stub) and update package.json scripts:
{
"scripts": {
"dev": "vite",
"build": "vite build"
}
}
Asset Organization Leverage Vite’s native support for:
resources/js/components/Button.js).@vitejs/plugin-react or @vitejs/plugin-vue for framework-specific optimizations.Environment-Specific Configs
Use vite.config.js to conditionally load assets:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/js/app.js'],
refresh: true,
}),
],
build: {
outDir: process.env.NODE_ENV === 'production'
? 'public/build'
: 'public/hot',
},
});
@vite(['resources/js/app.js']) in Blade templates for dynamic asset loading.vite.config.js for seamless dev experience:
server: {
hmr: {
host: 'localhost',
},
}
@vitejs/plugin-basic-ssl and configure tsconfig.json for type safety.Stub Overwrites
resources/js/app.js or vite.config.js. Backup files before running vendor:publish.--tag="vite-stubby" explicitly to avoid unintended overwrites.Port Conflicts
5173) may clash with other dev servers (e.g., Laravel Valet).devServerPort in config/vite-stubby.php or use:
VITE_PORT=3000 npm run dev
Missing Dependencies
laravel-vite-plugin or Vite core packages (vite, @vitejs/plugin-*) will break builds.package.json:
"devDependencies": {
"vite": "^4.0.0",
"laravel-vite-plugin": "^0.7.0"
}
Production Build Paths
/css/app.css) in Blade templates will fail in production if buildDirectory changes.mix() helper or Vite’s @vite() directive with dynamic paths:
@vite(['resources/css/app.css', 'resources/js/app.js'])
npm run build -- --debug for detailed Vite logs.php artisan config:clear and php artisan view:clear after config changes.Custom Stubs
Override published stubs by copying them to your project (e.g., resources/js/app.js) before installation.
Vite Plugins
Extend vite.config.js with plugins like:
import { VitePWA } from 'vite-plugin-pwa';
plugins: [laravel(), VitePWA({ registerType: 'autoUpdate' })]
CI/CD Optimization
Use Vite’s --mode production flag in CI for faster builds:
npm run build -- --mode production
Monorepo Support
Configure Vite to work with monorepos (e.g., Turborepo) by adjusting resolve.alias in vite.config.js.
How can I help you explore Laravel packages today?