Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ body:
- http-guzzle
- inertia
- inertia-react
- inertia-vue
- layout
- log
- log-file
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ body:
- http-guzzle
- inertia
- inertia-react
- inertia-vue
- layout
- log
- log-file
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@
"type": "path",
"url": "packages/inertia-react"
},
{
"type": "path",
"url": "packages/inertia-vue"
},
{
"type": "path",
"url": "packages/layout"
Expand Down Expand Up @@ -346,6 +350,7 @@
"marko/health": "self.version",
"marko/inertia": "self.version",
"marko/inertia-react": "self.version",
"marko/inertia-vue": "self.version",
"marko/http": "self.version",
"marko/layout": "self.version",
"marko/http-guzzle": "self.version",
Expand Down Expand Up @@ -453,6 +458,7 @@
"Marko\\Health\\Tests\\": "packages/health/tests/",
"Marko\\Inertia\\Tests\\": "packages/inertia/tests/",
"Marko\\Inertia\\React\\Tests\\": "packages/inertia-react/tests/",
"Marko\\Inertia\\Vue\\Tests\\": "packages/inertia-vue/tests/",
"Marko\\Http\\Tests\\": "packages/http/tests/",
"Marko\\Http\\Guzzle\\Tests\\": "packages/http-guzzle/tests/",
"Marko\\Layout\\Tests\\": "packages/layout/tests/",
Expand Down
109 changes: 109 additions & 0 deletions docs/src/content/docs/packages/inertia-vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
title: marko/inertia-vue
description: Vue 3 companion for marko/inertia - configuration defaults and a frontend marker binding for Vue.
---

Vue 3 companion for [`marko/inertia`](/docs/packages/inertia/) and [`marko/vite`](/docs/packages/vite/). It overlays the parent Inertia configuration with Vue defaults and registers a frontend marker binding so installing multiple Inertia frontend companions fails loudly.

## Installation

```bash
composer require marko/inertia-vue
```

Install the matching frontend dependencies in your app:

```bash
npm install @inertiajs/vue3 vue @vue/server-renderer @vitejs/plugin-vue vite
```

Refer to the [Inertia.js docs](https://inertiajs.com/) for currently supported versions of each frontend adapter.

## Configuration

This package contributes defaults to the parent `config/inertia.php` namespace:

```php title="packages/inertia-vue/config/inertia.php"
return [
'assetEntry' => env('INERTIA_VUE_CLIENT_ENTRY', 'app/vue-web/resources/js/app.js'),
];
```

| Key | Purpose |
| --- | --- |
| `assetEntry` | Vite entry used by browser-rendered Inertia responses. |

## Usage

Render Vue-backed Inertia pages without passing an asset entry; `marko/inertia` reads it from configuration:

```php
use Marko\Inertia\Inertia;
use Marko\Routing\Http\Request;
use Marko\Routing\Http\Response;

class DashboardController
{
public function __construct(
private readonly Inertia $inertia,
) {}

public function index(Request $request): Response
{
return $this->inertia->render(
request: $request,
component: 'Dashboard',
);
}
}
```

Create the client entry at `app/vue-web/resources/js/app.js`:

```js title="app/vue-web/resources/js/app.js"
import { createInertiaApp } from '@inertiajs/vue3';
import { createApp, h } from 'vue';

createInertiaApp({
resolve: (name) => {
const pages = import.meta.glob('./Pages/**/*.vue', { eager: true });
return pages[`./Pages/${name}.vue`];
},
setup({ el, App, props, plugin }) {
createApp({ render: () => h(App, props) }).use(plugin).mount(el);
},
});
```

Create the SSR entry at `app/vue-web/resources/js/ssr.js`:

```js title="app/vue-web/resources/js/ssr.js"
import { createInertiaApp } from '@inertiajs/vue3';
import createServer from '@inertiajs/vue3/server';
import { renderToString } from '@vue/server-renderer';
import { createSSRApp, h } from 'vue';

createServer((page) =>
createInertiaApp({
page,
render: renderToString,
resolve: (name) => {
const pages = import.meta.glob('./Pages/**/*.vue', { eager: true });
return pages[`./Pages/${name}.vue`];
},
setup({ App, props, plugin }) {
return createSSRApp({ render: () => h(App, props) }).use(plugin);
},
}),
);
```

## API Reference

This package registers `Marko\Inertia\Frontend\InertiaFrontendInterface` to a Vue marker implementation. Installing more than one Inertia frontend companion produces the same binding conflict protection used by Marko driver siblings.

## Related Packages

- [`marko/inertia`](/docs/packages/inertia/) - renders Inertia responses and handles SSR fallback
- [`marko/vite`](/docs/packages/vite/) - resolves the configured Vue Vite entry
- [`marko/env`](/docs/packages/env/) - provides the `env()` helper used in `config/inertia.php`
5 changes: 5 additions & 0 deletions packages/inertia-vue/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/tests export-ignore
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
20 changes: 20 additions & 0 deletions packages/inertia-vue/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) Devtomic LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 36 additions & 0 deletions packages/inertia-vue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# marko/inertia-vue

Vue 3 companion for `marko/inertia` - configuration defaults and a frontend marker binding for Vue.

## Installation

```bash
composer require marko/inertia-vue
```

## Quick Example

```php
use Marko\Inertia\Inertia;
use Marko\Routing\Http\Request;
use Marko\Routing\Http\Response;

class DashboardController
{
public function __construct(
private readonly Inertia $inertia,
) {}

public function index(Request $request): Response
{
return $this->inertia->render(
request: $request,
component: 'Dashboard',
);
}
}
```

## Documentation

Full usage, API reference, and examples: [marko/inertia-vue](https://marko.build/docs/packages/inertia-vue/)
28 changes: 28 additions & 0 deletions packages/inertia-vue/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "marko/inertia-vue",
"description": "Vue 3 companion for marko/inertia - configuration and frontend marker binding",
"license": "MIT",
"type": "marko-module",
"require": {
"php": "^8.5",
"marko/core": "self.version",
"marko/env": "self.version",
"marko/inertia": "self.version",
"marko/vite": "self.version"
},
"autoload": {
"psr-4": {
"Marko\\Inertia\\Vue\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Marko\\Inertia\\Vue\\Tests\\": "tests/"
}
},
"extra": {
"marko": {
"module": true
}
}
}
7 changes: 7 additions & 0 deletions packages/inertia-vue/config/inertia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

return [
'assetEntry' => env('INERTIA_VUE_CLIENT_ENTRY', 'app/vue-web/resources/js/app.js'),
];
12 changes: 12 additions & 0 deletions packages/inertia-vue/module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use Marko\Inertia\Frontend\InertiaFrontendInterface;
use Marko\Inertia\Vue\VueInertiaFrontend;

return [
'bindings' => [
InertiaFrontendInterface::class => VueInertiaFrontend::class,
],
];
15 changes: 15 additions & 0 deletions packages/inertia-vue/src/VueInertiaFrontend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Marko\Inertia\Vue;

use Marko\Inertia\Frontend\InertiaFrontendInterface;

class VueInertiaFrontend implements InertiaFrontendInterface
{
public function name(): string
{
return 'vue';
}
}
36 changes: 36 additions & 0 deletions packages/inertia-vue/tests/InertiaVueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

use Marko\Inertia\Frontend\InertiaFrontendInterface;
use Marko\Inertia\Vue\VueInertiaFrontend;

test('inertia-vue config overlays the parent inertia config', function () {
$config = require dirname(__DIR__).'/config/inertia.php';

expect($config['assetEntry'])->toBe('app/vue-web/resources/js/app.js');
expect($config)->not->toHaveKey('ssrEntry');
});

test('inertia-vue binds the inertia frontend marker', function () {
$module = require dirname(__DIR__).'/module.php';

expect($module['bindings'])->toHaveKey(InertiaFrontendInterface::class)
->and($module['bindings'][InertiaFrontendInterface::class])->toBe(VueInertiaFrontend::class);
});

test('vue inertia frontend identifies itself', function () {
expect((new VueInertiaFrontend())->name())->toBe('vue');
});

test('inertia-vue is a marko module', function () {
$composer = json_decode(
file_get_contents(dirname(__DIR__).'/composer.json'),
true,
flags: JSON_THROW_ON_ERROR,
);

expect(file_exists(dirname(__DIR__).'/module.php'))->toBeTrue()
->and($composer['extra']['marko']['module'])->toBeTrue()
->and($composer['autoload']['psr-4'])->toHaveKey('Marko\\Inertia\\Vue\\');
});