machinjiri-vite-plugin
v1.2.0
Published
Vite plugin for Machinjiri framework integration
Downloads
27
Maintainers
Readme
# Machinjiri Vite Plugin
Seamless integration between [Vite](https://vitejs.dev) and the Machinjiri PHP framework.
- Hot Module Replacement (HMR) during development
- Automatic manifest generation for asset versioning
- Optional full-page reload on Blade‑like template changes
- Zero‑config setup for standard Machinjiri project structures
## Installation
```bash
npm install machinjiri-vite-plugin --save-devThis plugin assumes you have Vite installed in your project. If not:
npm install vite --save-devBasic Usage
Create a vite.config.js file in your project root:
import machinjiri from 'machinjiri-vite-plugin';
export default {
plugins: [
machinjiri('resources/js/app.js', {
refresh: true,
}),
],
};Then in your Machinjiri layout/view file, include the Vite assets using the @vite directive (provided by the framework) or manually:
<!-- Development (hot file exists) -->
<script type="module" src="http://localhost:5173/@vite/client"></script>
<script type="module" src="http://localhost:5173/resources/js/app.js"></script>
<!-- Production (build manifest used) -->
<link rel="stylesheet" href="/build/assets/app-*.css">
<script type="module" src="/build/assets/app-*.js"></script>Configuration
The plugin accepts two arguments:
machinjiri(input, options)input
Type: string | string[] Default: none (required)
Entry point(s) relative to the project root. Example: 'resources/js/app.js' or ['resources/js/app.js', 'resources/css/admin.css'].
options
Option Type Default Description refresh boolean false Enable full page reload when template files change. refreshPaths string | string[] [] Additional paths to watch for reload (supports glob patterns). publicDirectory string 'public' Directory where assets are publicly served. buildDirectory string 'build' Subdirectory inside publicDirectory where built assets are placed. hotFile string public/hot Path where the dev server URL is stored (used by PHP to detect dev mode).
Examples
Multiple entry points with custom build output
machinjiri([
'resources/js/app.js',
'resources/css/admin.css',
'resources/js/editor.js'
], {
publicDirectory: 'public_html',
buildDirectory: 'assets',
})Enable refresh with additional watch paths
machinjiri('resources/js/app.js', {
refresh: true,
refreshPaths: ['app/Views/**/*.mg.php', 'config/*.php'],
})How It Works
Development Mode
· A hot file is created in the public directory containing the Vite dev server URL. · The Machinjiri framework detects this file and loads assets from the dev server. · HMR updates modules without a full page reload. · If refresh: true, changes to template files (*.mg.php, *.blade.php) trigger a full browser refresh.
Production Build
· Running vite build outputs minified assets to {publicDirectory}/{buildDirectory}. · A manifest.json file is generated to map original entry points to their hashed versions. · The framework reads the manifest to include the correct asset URLs.
Framework Integration
This plugin is designed for the Machinjiri PHP framework. If you're using a custom or different framework, ensure it:
· Checks for the existence of the hot file to switch between dev and production asset URLs. · Reads the manifest.json file to resolve asset paths in production.
License
MIT © Precious Lyson
Contributing
Issues and pull requests are welcome. Please ensure your code follows the existing style and includes appropriate tests.
