Download the PHP package inventor96/inertia-mako without Composer
On this page you can find all versions of the php package inventor96/inertia-mako. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download inventor96/inertia-mako
More information about inventor96/inertia-mako
Files in inventor96/inertia-mako
Package inertia-mako
Short Description The Mako adapter for Inertia.js.
License MIT
Informations about the package inertia-mako
Inertia.js Mako Adapter
An Inertia.js server-side adapter for the PHP Mako framework.
The examples below are for Vue.js.
Installation
-
Install the composer and npm packages:
Yes, the laravel vite plugin is intentional. We could create our own, but that would pretty much be reinventing the wheel, or just changing the name while the underlying code is untouched. Note that when running
npm run dev
later, the Laravel plugin will report theAPP_URL
as undefined, but that's OK for our situation. -
Set other npm configs:
package.json
-
Create the vite config:
vite.config.js
-
Create the JS app file:
app/resources/js/app.js
-
Enable the package in Mako:
app/config/application.php
- Register the middleware:
app/http/routing/middleware.php
Configuration
If you would like to override the default configuration, create a new file at app/config/packages/inertia/inertia.php
.
The following configuration items and their defaults are as follows:
For vite-specific configurations, create a vite.php
config file in the same directory.
Using a Custom html_template
You will probably want to create your own html_template
at some point in your project. There are 3 values passed to the template from the InertiaRenderer
. You can add to these using built-in Mako functionality.
$title
: Just a pass-thru of thetitle
config var above. This is optional to use.$page
: The JSON Inertia page object. You have to use this somewhere for Inertia to work.$tags
: The HTML tags for Vite resources. It contains three string properties:js
,css
, andpreload
. You have to use at least thejs
property somewhere for Inertia to work.
Here is the default page used in this inertia-mako
package:
Coding Your App
The idea of this InertiaJS adapter is to utilize existing Mako framework functionality. As such, it's built to have the Vue files be organized under app/resources/views/
. Pages should be under the Pages/
folder. For example:
In your routes or controllers, you can use the Mako ViewFactory::render()
method to handle the InertiaJS response, prefixing the path with Pages/
. e.g. $view->render('Pages/Welcome')
.
The Inertia
class is registered in the Mako dependency injection container under the inertia
key. So as an alternative to using the ViewFactory
with the path prefix, you call $this->inertia->render('Welcome')
. This is just a wrapper around the original method, so there's really no difference under the hood. It's just there for personal preference sake.
Asset Versioning
Inertia.js features asset versioning to mitigate stale client-side caching. To indicate the server-side version, create a file at app/config/packages/inertia/version.php
that functions like the following:
You can make that file do whatever you need to come up with your verison. The only requirement is that it ultimately returns an array with a single string value (the array is requirement is due to how Mako configs work).
Commit Hash Versioning
One common way to version assets is to use the commit hash of the current git commit. You can do this by creating a file at app/config/packages/inertia/version.php
that looks like this:
This approach checks the filesystem rather than using the git
command, so it should work on any system that has a .git
directory. If you are using a CI/CD pipeline, you may need to adjust the path to the .git
directory.
All versions of inertia-mako with dependencies
ext-json Version *
mako/framework Version ^10.0
mindplay/php-vite Version ^1.0