Repository navigation
Asset Bundling
Laravex uses Vite to bundle frontend assets — JavaScript, CSS, and any other resources declared in vite.config.js. The integration mirrors Laravel's first-party Vite plugin: a @vite Blade directive switches automatically between HMR dev-server URLs and production manifest paths.
laravex/
├── resources/
│ ├── css/
│ │ └── app.css # main stylesheet entry point
│ └── js/
│ └── app.js # main JavaScript entry point
├── public/
│ ├── build/ # compiled assets (committed or deployed)
│ │ ├── app.css
│ │ └── app.js
│ └── hot # written by `vite --watch`; signals dev mode
└── vite.config.js
vite.config.js at the project root:
// vite.config.js
export default {
build: {
outDir: "public/build",
rollupOptions: {
input: ["resources/css/app.css", "resources/js/app.js"],
},
},
};| Option | Value |
|---|---|
build.outDir |
public/build — compiled files land here |
rollupOptions.input |
Entry points fed to Rollup during vite build
|
Add additional entry points to the input array as needed (e.g. page-specific JS, TypeScript files).
Development (HMR)
npx vite
# or
npm run devVite starts its dev server and writes public/hot containing the base URL (e.g. http://localhost:5173). While public/hot is present, the @vite directive emits HMR-aware <script type="module"> and <link rel="stylesheet"> tags pointing at the dev server.
Production build
npx vite build
# or
npm run buildCompiles and writes fingerprinted assets to public/build/. Removes (or never creates) public/hot, so the @vite directive falls back to static public/build/ paths.
Include your entry points in the layout's <head>:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body>
@yield('content')
</body>
</html>Development output (when public/hot contains http://localhost:5173):
<link rel="stylesheet" href="http://localhost:5173/resources/css/app.css">
<script type="module" src="http://localhost:5173/resources/js/app.js"></script>Production output (no public/hot file):
<link rel="stylesheet" href="/build/css/app.css">
<script type="module" src="/build/app.js"></script>Asset detection is based on file extension: .css files emit <link> tags; everything else emits <script type="module"> tags.
The Laravex.Vite.tags/1 function (called by the @vite Blade directive) checks for public/hot at startup:
- Hot file present — reads the URL from the file, prepends it to each asset path, and emits HMR tags.
-
No hot file — strips the
resources/prefix from each asset path and emits static/build/…tags.
# Equivalent Elixir call (usually done via @vite in a template)
Laravex.Vite.tags(["resources/css/app.css", "resources/js/app.js"])resources/js/app.js is the JavaScript bootstrap:
// resources/js/app.js
console.log("Laravex assets loaded");
// import Alpine from 'alpinejs';
// import './bootstrap';resources/css/app.css is the global stylesheet:
/* resources/css/app.css */
body {
margin: 0;
}Replace or extend these files as your application grows.
Add convenience scripts to package.json:
{
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"vite": "^5.0.0"
}
}-
Views — rendering templates that use
@vite -
Blade-Templates#Vite Assets — the
@vitedirective reference
Laravex — Laravel-faithful application skeleton & runtime for Elixir.
GitHub
·
Docs
·
Limitations
·
Laravel Docs
Not affiliated with Laravel LLC or the Elixir core team. Built to feel like Laravel on the BEAM.
- Home
- Installation
- Configuration
- Directory-Structure
- Request-Lifecycle
- Service-Container
- Service-Providers
- Deployment
- Routing
- Middleware
- CSRF-Protection
- Controllers
- Requests
- Responses
- Views
- Blade-Templates
- Asset-Bundling
- Session
- Validation
- Error-Handling
- Logging
- Artisan-Console
- Broadcasting
- Cache
- Collections
- Events
- File-Storage
- Helpers
- HTTP-Client
- Localization
- Notifications
- Pipeline
- Queues
- Rate-Limiting
- Strings
- Task-Scheduling