This package supports two major workflows for handling frontend assets:
public/ for simple serving.Laravel Modular is designed to work seamlessly with Vite.
To enable Vite to "see" your module assets, you need to tell it where to look.
Create a vite.modular.js (or similar) helper to glob your module inputs:
// vite.modular.js
import { globSync } from "glob";
export const modularLoader = {
inputs() {
// Scans all modules for JS/CSS entry points
return globSync("modules/*/resources/assets/{css,js,ts}/*.{css,js,ts}");
},
refreshPaths() {
// Tells Vite to reload when you edit a module's blade file
return ["modules/*/resources/views/**/*.blade.php"];
},
};
vite.config.jsImport the helper and add it to the Laravel plugin config.
import { defineConfig } from "vite";
import laravel from "laravel-vite-plugin";
import { modularLoader } from "./vite.modular.js";
export default defineConfig({
plugins: [
laravel({
input: [
"resources/css/app.css",
"resources/js/app.js",
...modularLoader.inputs(), // <--- Auto-discover module assets
],
refresh: [
...modularLoader.refreshPaths(), // <--- Auto-refresh on changes
],
}),
],
});
Use the global helper modular_vite() to inject the script tags. This wrapper automatically points to the correct build directory.
<head>
<!-- Loads main app assets -->
[@vite](https://github.com/vite)(['resources/css/app.css', 'resources/js/app.js'])
<!-- Loads module assets -->
{{ modular_vite([
'modules/Shop/resources/assets/css/app.css',
'modules/Shop/resources/assets/js/app.js'
]) }}
</head>
Laravel Modular dynamically registers Blade Component Namespaces for all of your modules automatically. Whether you are using anonymous blade components or strictly-typed PHP class components, everything resolves perfectly natively!
If you create a component inside modules/Shop/app/View/Components/Alert.php and a view in modules/Shop/resources/views/components/alert.blade.php:
// modules/Shop/app/View/Components/Alert.php
namespace Modules\Shop\View\Components;
use Illuminate\View\Component;
class Alert extends Component
{
public function render() {
return view('shop::components.alert');
}
}
You can render it seamlessly anywhere using the standard native Laravel syntax:
<x-shop::alert type="success" message="Payment Processed!" />
The underlying architecture flawlessly maps shop:: straight to the Modules\Shop\View\Components namespace!
Each module is treated as a separate package with its own package.json.
Do not run npm install inside the module directory manually. Instead, use the modular:npm command to ensure context is correct (especially if using workspaces).
# Install 'chart.js' into the 'Dashboard' module
php artisan modular:npm Dashboard install chart.js
You can run any script defined in a module's package.json.
# Run 'build' script for 'Dashboard'
php artisan modular:npm Dashboard run build
modular:link)If you have static images, fonts, or compiled CSS/JS that you simply want to serve from the public/ directory without Vite build steps:
modules/{Module}/resources/assets.php artisan modular:link
This creates a symbolic link:
public/modules/shop -> modules/Shop/resources/assets
You can then reference them:
<img src="{{ module_asset('Shop', 'images/logo.png') }}" />
{{-- Resolves to: http://site.test/modules/shop/images/logo.png --}}
How can I help you explore Laravel packages today?