From ca4b0042bd4043a73fad2ddf4cbd14f470032a5a Mon Sep 17 00:00:00 2001 From: Paulo Carvalho Date: Sat, 25 Apr 2026 12:20:32 +0100 Subject: [PATCH 1/4] Add marko inertia vue package --- .github/ISSUE_TEMPLATE/bug_report.yml | 1 + .github/ISSUE_TEMPLATE/feature_request.yml | 1 + composer.json | 6 ++ packages/inertia-vue/.gitattributes | 5 ++ packages/inertia-vue/LICENSE | 20 ++++++ packages/inertia-vue/README.md | 62 +++++++++++++++++++ packages/inertia-vue/composer.json | 28 +++++++++ packages/inertia-vue/config/inertia-vue.php | 14 +++++ packages/inertia-vue/module.php | 10 +++ packages/inertia-vue/tests/InertiaVueTest.php | 21 +++++++ 10 files changed, 168 insertions(+) create mode 100644 packages/inertia-vue/.gitattributes create mode 100644 packages/inertia-vue/LICENSE create mode 100644 packages/inertia-vue/README.md create mode 100644 packages/inertia-vue/composer.json create mode 100644 packages/inertia-vue/config/inertia-vue.php create mode 100644 packages/inertia-vue/module.php create mode 100644 packages/inertia-vue/tests/InertiaVueTest.php diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index aab8fb18..8d25f027 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -83,6 +83,7 @@ body: - http-guzzle - inertia - inertia-react + - inertia-vue - layout - log - log-file diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 9daf1825..1e090a3e 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -71,6 +71,7 @@ body: - http-guzzle - inertia - inertia-react + - inertia-vue - layout - log - log-file diff --git a/composer.json b/composer.json index 0216e968..1804ddf5 100644 --- a/composer.json +++ b/composer.json @@ -148,6 +148,10 @@ "type": "path", "url": "packages/inertia-react" }, + { + "type": "path", + "url": "packages/inertia-vue" + }, { "type": "path", "url": "packages/layout" @@ -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", @@ -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\\InertiaVue\\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/", diff --git a/packages/inertia-vue/.gitattributes b/packages/inertia-vue/.gitattributes new file mode 100644 index 00000000..e5736f06 --- /dev/null +++ b/packages/inertia-vue/.gitattributes @@ -0,0 +1,5 @@ +/tests export-ignore +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/phpunit.xml.dist export-ignore diff --git a/packages/inertia-vue/LICENSE b/packages/inertia-vue/LICENSE new file mode 100644 index 00000000..99a76f97 --- /dev/null +++ b/packages/inertia-vue/LICENSE @@ -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. diff --git a/packages/inertia-vue/README.md b/packages/inertia-vue/README.md new file mode 100644 index 00000000..b32bd562 --- /dev/null +++ b/packages/inertia-vue/README.md @@ -0,0 +1,62 @@ +# Marko Inertia Vue + +Configuration defaults for Vue 3 apps built with `marko/inertia` and `marko/vite`. + +## Install + +```bash +composer require marko/inertia marko/inertia-vue marko/vite +npm install @inertiajs/vue3@^3.0 vue@^3.5 @vue/server-renderer@^3.5 @vitejs/plugin-vue@^6.0 vite@^8.0 +``` + +## Files + +Create the client entry at `app/vue-web/resources/js/app.js`: + +```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 +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); + }, + }), +); +``` + +## Configuration + +The package exposes: + +- `clientEntry`: `app/vue-web/resources/js/app.js` +- `ssrEntry`: `app/vue-web/resources/js/ssr.js` +- `ssrBundle`: `bootstrap/ssr/vue/ssr.js` + +Override them with `INERTIA_VUE_CLIENT_ENTRY`, `INERTIA_VUE_SSR_ENTRY`, and `INERTIA_VUE_SSR_BUNDLE`. diff --git a/packages/inertia-vue/composer.json b/packages/inertia-vue/composer.json new file mode 100644 index 00000000..cc0b7e2a --- /dev/null +++ b/packages/inertia-vue/composer.json @@ -0,0 +1,28 @@ +{ + "name": "marko/inertia-vue", + "type": "marko-module", + "description": "Vue 3 companion for marko/inertia — scaffolding and SSR server entry point", + "license": "MIT", + "require": { + "php": "^8.5", + "marko/core": "self.version", + "marko/env": "self.version", + "marko/inertia": "self.version", + "marko/vite": "self.version" + }, + "autoload": { + "psr-4": { + "Marko\\InertiaVue\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Marko\\InertiaVue\\Tests\\": "tests/" + } + }, + "extra": { + "marko": { + "module": true + } + } +} diff --git a/packages/inertia-vue/config/inertia-vue.php b/packages/inertia-vue/config/inertia-vue.php new file mode 100644 index 00000000..bc9e60a6 --- /dev/null +++ b/packages/inertia-vue/config/inertia-vue.php @@ -0,0 +1,14 @@ + env('INERTIA_VUE_CLIENT_ENTRY', 'app/vue-web/resources/js/app.js'), + 'ssrEntry' => env('INERTIA_VUE_SSR_ENTRY', 'app/vue-web/resources/js/ssr.js'), + 'ssrBundle' => env('INERTIA_VUE_SSR_BUNDLE', $basePath.'/bootstrap/ssr/vue/ssr.js'), +]; diff --git a/packages/inertia-vue/module.php b/packages/inertia-vue/module.php new file mode 100644 index 00000000..12a179a2 --- /dev/null +++ b/packages/inertia-vue/module.php @@ -0,0 +1,10 @@ + true, + 'sequence' => [ + 'after' => ['marko/inertia', 'marko/vite'], + ], +]; diff --git a/packages/inertia-vue/tests/InertiaVueTest.php b/packages/inertia-vue/tests/InertiaVueTest.php new file mode 100644 index 00000000..81cad996 --- /dev/null +++ b/packages/inertia-vue/tests/InertiaVueTest.php @@ -0,0 +1,21 @@ +toBe('app/vue-web/resources/js/app.js'); + expect($config['ssrEntry'])->toBe('app/vue-web/resources/js/ssr.js'); + expect($config['ssrBundle'])->toBe('/var/www/bootstrap/ssr/vue/ssr.js'); +}); + +test('inertia-vue module depends on inertia and vite', function () { + $module = require dirname(__DIR__).'/module.php'; + + expect($module['enabled'])->toBeTrue(); + expect($module['sequence']['after'])->toContain('marko/inertia'); + expect($module['sequence']['after'])->toContain('marko/vite'); +}); From 7fa5bb58b8ac1a5167b77e1482aef93610e6e12d Mon Sep 17 00:00:00 2001 From: Paulo Carvalho Date: Fri, 1 May 2026 20:35:48 +0100 Subject: [PATCH 2/4] refactor: align marko/inertia-vue with package conventions and add docs page --- docs/src/content/docs/packages/inertia-vue.md | 112 ++++++++++++++++++ packages/inertia-vue/.gitattributes | 2 +- packages/inertia-vue/README.md | 81 +++++-------- packages/inertia-vue/composer.json | 45 ++++--- packages/inertia-vue/config/inertia-vue.php | 7 +- packages/inertia-vue/module.php | 10 -- packages/inertia-vue/tests/InertiaVueTest.php | 17 +-- 7 files changed, 171 insertions(+), 103 deletions(-) create mode 100644 docs/src/content/docs/packages/inertia-vue.md delete mode 100644 packages/inertia-vue/module.php diff --git a/docs/src/content/docs/packages/inertia-vue.md b/docs/src/content/docs/packages/inertia-vue.md new file mode 100644 index 00000000..cd78bf23 --- /dev/null +++ b/docs/src/content/docs/packages/inertia-vue.md @@ -0,0 +1,112 @@ +--- +title: marko/inertia-vue +description: Vue 3 companion for marko/inertia - configuration defaults for Vue client and SSR entries. +--- + +Vue 3 companion for [`marko/inertia`](/docs/packages/inertia/) and [`marko/vite`](/docs/packages/vite/). It ships Marko configuration defaults for Vue client and SSR entrypoints while leaving the JavaScript application code in your project. + +## Installation + +```bash +composer require marko/inertia-vue +``` + +Install the matching frontend dependencies in your app: + +```bash +npm install @inertiajs/vue3@^3.0 vue@^3.5 @vue/server-renderer@^3.5 @vitejs/plugin-vue@^6.0 vite@^8.0 +``` + +## Configuration + +Configure via `config/inertia-vue.php`: + +```php title="config/inertia-vue.php" +return [ + 'clientEntry' => env('INERTIA_VUE_CLIENT_ENTRY', 'app/vue-web/resources/js/app.js'), + 'ssrEntry' => env('INERTIA_VUE_SSR_ENTRY', 'app/vue-web/resources/js/ssr.js'), + 'ssrBundle' => env('INERTIA_VUE_SSR_BUNDLE', 'bootstrap/ssr/vue/ssr.js'), +]; +``` + +| Key | Purpose | +| --- | --- | +| `clientEntry` | Vite entry used by browser-rendered Inertia responses. | +| `ssrEntry` | Vite entry used to build the Vue SSR server bundle. | +| `ssrBundle` | Relative path to the built SSR bundle loaded by your SSR runner. | + +## Usage + +Use the configured client entry when rendering Vue-backed Inertia pages: + +```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', + assetEntry: 'app/vue-web/resources/js/app.js', + ); + } +} +``` + +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 is configuration-only. It does not add PHP services or bindings; `module.php` is intentionally omitted because Marko can discover the package through Composer metadata and load its `config/` directory without explicit module options. + +## 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-vue.php` diff --git a/packages/inertia-vue/.gitattributes b/packages/inertia-vue/.gitattributes index e5736f06..aa78278f 100644 --- a/packages/inertia-vue/.gitattributes +++ b/packages/inertia-vue/.gitattributes @@ -1,5 +1,5 @@ /tests export-ignore -/.github export-ignore +/.github export-ignore /.gitattributes export-ignore /.gitignore export-ignore /phpunit.xml.dist export-ignore diff --git a/packages/inertia-vue/README.md b/packages/inertia-vue/README.md index b32bd562..9a29a72b 100644 --- a/packages/inertia-vue/README.md +++ b/packages/inertia-vue/README.md @@ -1,62 +1,37 @@ -# Marko Inertia Vue +# marko/inertia-vue -Configuration defaults for Vue 3 apps built with `marko/inertia` and `marko/vite`. +Vue 3 companion for `marko/inertia` - configuration for Vue client and SSR entries. -## Install +## Installation ```bash -composer require marko/inertia marko/inertia-vue marko/vite -npm install @inertiajs/vue3@^3.0 vue@^3.5 @vue/server-renderer@^3.5 @vitejs/plugin-vue@^6.0 vite@^8.0 +composer require marko/inertia-vue ``` -## Files - -Create the client entry at `app/vue-web/resources/js/app.js`: - -```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); - }, -}); +## 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', + assetEntry: 'app/vue-web/resources/js/app.js', + ); + } +} ``` -Create the SSR entry at `app/vue-web/resources/js/ssr.js`: - -```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); - }, - }), -); -``` - -## Configuration - -The package exposes: - -- `clientEntry`: `app/vue-web/resources/js/app.js` -- `ssrEntry`: `app/vue-web/resources/js/ssr.js` -- `ssrBundle`: `bootstrap/ssr/vue/ssr.js` +## Documentation -Override them with `INERTIA_VUE_CLIENT_ENTRY`, `INERTIA_VUE_SSR_ENTRY`, and `INERTIA_VUE_SSR_BUNDLE`. +Full usage, API reference, and examples: [marko/inertia-vue](https://marko.build/docs/packages/inertia-vue/) diff --git a/packages/inertia-vue/composer.json b/packages/inertia-vue/composer.json index cc0b7e2a..19d3d1d9 100644 --- a/packages/inertia-vue/composer.json +++ b/packages/inertia-vue/composer.json @@ -1,28 +1,23 @@ { - "name": "marko/inertia-vue", - "type": "marko-module", - "description": "Vue 3 companion for marko/inertia — scaffolding and SSR server entry point", - "license": "MIT", - "require": { - "php": "^8.5", - "marko/core": "self.version", - "marko/env": "self.version", - "marko/inertia": "self.version", - "marko/vite": "self.version" - }, - "autoload": { - "psr-4": { - "Marko\\InertiaVue\\": "src/" + "name": "marko/inertia-vue", + "description": "Vue 3 companion for marko/inertia - configuration for Vue client and SSR entries", + "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-dev": { + "psr-4": { + "Marko\\InertiaVue\\Tests\\": "tests/" + } + }, + "extra": { + "marko": { + "module": true + } } - }, - "autoload-dev": { - "psr-4": { - "Marko\\InertiaVue\\Tests\\": "tests/" - } - }, - "extra": { - "marko": { - "module": true - } - } } diff --git a/packages/inertia-vue/config/inertia-vue.php b/packages/inertia-vue/config/inertia-vue.php index bc9e60a6..98439b74 100644 --- a/packages/inertia-vue/config/inertia-vue.php +++ b/packages/inertia-vue/config/inertia-vue.php @@ -2,13 +2,8 @@ declare(strict_types=1); -$documentRoot = $_SERVER['DOCUMENT_ROOT'] ?? null; -$basePath = is_string($documentRoot) && $documentRoot !== '' - ? dirname($documentRoot) - : (getcwd() ?: ''); - return [ 'clientEntry' => env('INERTIA_VUE_CLIENT_ENTRY', 'app/vue-web/resources/js/app.js'), 'ssrEntry' => env('INERTIA_VUE_SSR_ENTRY', 'app/vue-web/resources/js/ssr.js'), - 'ssrBundle' => env('INERTIA_VUE_SSR_BUNDLE', $basePath.'/bootstrap/ssr/vue/ssr.js'), + 'ssrBundle' => env('INERTIA_VUE_SSR_BUNDLE', 'bootstrap/ssr/vue/ssr.js'), ]; diff --git a/packages/inertia-vue/module.php b/packages/inertia-vue/module.php deleted file mode 100644 index 12a179a2..00000000 --- a/packages/inertia-vue/module.php +++ /dev/null @@ -1,10 +0,0 @@ - true, - 'sequence' => [ - 'after' => ['marko/inertia', 'marko/vite'], - ], -]; diff --git a/packages/inertia-vue/tests/InertiaVueTest.php b/packages/inertia-vue/tests/InertiaVueTest.php index 81cad996..9c35309a 100644 --- a/packages/inertia-vue/tests/InertiaVueTest.php +++ b/packages/inertia-vue/tests/InertiaVueTest.php @@ -3,19 +3,20 @@ declare(strict_types=1); test('inertia-vue config loads client and ssr entries', function () { - $_SERVER['DOCUMENT_ROOT'] = '/var/www/public'; - $config = require dirname(__DIR__).'/config/inertia-vue.php'; expect($config['clientEntry'])->toBe('app/vue-web/resources/js/app.js'); expect($config['ssrEntry'])->toBe('app/vue-web/resources/js/ssr.js'); - expect($config['ssrBundle'])->toBe('/var/www/bootstrap/ssr/vue/ssr.js'); + expect($config['ssrBundle'])->toBe('bootstrap/ssr/vue/ssr.js'); }); -test('inertia-vue module depends on inertia and vite', function () { - $module = require dirname(__DIR__).'/module.php'; +test('inertia-vue is a config-only marko module', function () { + $composer = json_decode( + file_get_contents(dirname(__DIR__).'/composer.json'), + true, + flags: JSON_THROW_ON_ERROR, + ); - expect($module['enabled'])->toBeTrue(); - expect($module['sequence']['after'])->toContain('marko/inertia'); - expect($module['sequence']['after'])->toContain('marko/vite'); + expect(file_exists(dirname(__DIR__).'/module.php'))->toBeFalse() + ->and($composer['extra']['marko']['module'])->toBeTrue(); }); From 85e59f6ba752da5aedb1bd8c07879607afaa057c Mon Sep 17 00:00:00 2001 From: Paulo Carvalho Date: Fri, 1 May 2026 23:20:26 +0100 Subject: [PATCH 3/4] refactor: wire inertia vue companion through parent config --- docs/src/content/docs/packages/inertia-vue.md | 31 ++++++++++--------- packages/inertia-vue/README.md | 3 +- packages/inertia-vue/composer.json | 7 ++++- packages/inertia-vue/config/inertia-vue.php | 9 ------ packages/inertia-vue/config/inertia.php | 10 ++++++ packages/inertia-vue/module.php | 12 +++++++ .../inertia-vue/src/VueInertiaFrontend.php | 15 +++++++++ packages/inertia-vue/tests/InertiaVueTest.php | 31 ++++++++++++++----- 8 files changed, 83 insertions(+), 35 deletions(-) delete mode 100644 packages/inertia-vue/config/inertia-vue.php create mode 100644 packages/inertia-vue/config/inertia.php create mode 100644 packages/inertia-vue/module.php create mode 100644 packages/inertia-vue/src/VueInertiaFrontend.php diff --git a/docs/src/content/docs/packages/inertia-vue.md b/docs/src/content/docs/packages/inertia-vue.md index cd78bf23..7f676df8 100644 --- a/docs/src/content/docs/packages/inertia-vue.md +++ b/docs/src/content/docs/packages/inertia-vue.md @@ -1,9 +1,9 @@ --- title: marko/inertia-vue -description: Vue 3 companion for marko/inertia - configuration defaults for Vue client and SSR entries. +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 ships Marko configuration defaults for Vue client and SSR entrypoints while leaving the JavaScript application code in your project. +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 @@ -14,30 +14,32 @@ composer require marko/inertia-vue Install the matching frontend dependencies in your app: ```bash -npm install @inertiajs/vue3@^3.0 vue@^3.5 @vue/server-renderer@^3.5 @vitejs/plugin-vue@^6.0 vite@^8.0 +npm install @inertiajs/vue3 vue @vue/server-renderer @vitejs/plugin-vue vite ``` +Refer to the Inertia.js docs for currently supported versions of each frontend adapter. + ## Configuration -Configure via `config/inertia-vue.php`: +This package contributes defaults to the parent `config/inertia.php` namespace: -```php title="config/inertia-vue.php" +```php title="packages/inertia-vue/config/inertia.php" return [ - 'clientEntry' => env('INERTIA_VUE_CLIENT_ENTRY', 'app/vue-web/resources/js/app.js'), - 'ssrEntry' => env('INERTIA_VUE_SSR_ENTRY', 'app/vue-web/resources/js/ssr.js'), - 'ssrBundle' => env('INERTIA_VUE_SSR_BUNDLE', 'bootstrap/ssr/vue/ssr.js'), + 'assetEntry' => env('INERTIA_VUE_CLIENT_ENTRY', 'app/vue-web/resources/js/app.js'), + 'ssr' => [ + 'bundle' => env('INERTIA_VUE_SSR_BUNDLE', 'bootstrap/ssr/vue/ssr.js'), + ], ]; ``` | Key | Purpose | | --- | --- | -| `clientEntry` | Vite entry used by browser-rendered Inertia responses. | -| `ssrEntry` | Vite entry used to build the Vue SSR server bundle. | -| `ssrBundle` | Relative path to the built SSR bundle loaded by your SSR runner. | +| `assetEntry` | Vite entry used by browser-rendered Inertia responses. | +| `ssr.bundle` | Relative path to the built SSR bundle loaded by your SSR runner. | ## Usage -Use the configured client entry when rendering Vue-backed Inertia pages: +Render Vue-backed Inertia pages without passing an asset entry; `marko/inertia` reads it from configuration: ```php use Marko\Inertia\Inertia; @@ -55,7 +57,6 @@ class DashboardController return $this->inertia->render( request: $request, component: 'Dashboard', - assetEntry: 'app/vue-web/resources/js/app.js', ); } } @@ -103,10 +104,10 @@ createServer((page) => ## API Reference -This package is configuration-only. It does not add PHP services or bindings; `module.php` is intentionally omitted because Marko can discover the package through Composer metadata and load its `config/` directory without explicit module options. +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-vue.php` +- [`marko/env`](/docs/packages/env/) - provides the `env()` helper used in `config/inertia.php` diff --git a/packages/inertia-vue/README.md b/packages/inertia-vue/README.md index 9a29a72b..298c37c1 100644 --- a/packages/inertia-vue/README.md +++ b/packages/inertia-vue/README.md @@ -1,6 +1,6 @@ # marko/inertia-vue -Vue 3 companion for `marko/inertia` - configuration for Vue client and SSR entries. +Vue 3 companion for `marko/inertia` - configuration defaults and a frontend marker binding for Vue. ## Installation @@ -26,7 +26,6 @@ class DashboardController return $this->inertia->render( request: $request, component: 'Dashboard', - assetEntry: 'app/vue-web/resources/js/app.js', ); } } diff --git a/packages/inertia-vue/composer.json b/packages/inertia-vue/composer.json index 19d3d1d9..1e3109c8 100644 --- a/packages/inertia-vue/composer.json +++ b/packages/inertia-vue/composer.json @@ -1,6 +1,6 @@ { "name": "marko/inertia-vue", - "description": "Vue 3 companion for marko/inertia - configuration for Vue client and SSR entries", + "description": "Vue 3 companion for marko/inertia - configuration and frontend marker binding", "license": "MIT", "type": "marko-module", "require": { @@ -10,6 +10,11 @@ "marko/inertia": "self.version", "marko/vite": "self.version" }, + "autoload": { + "psr-4": { + "Marko\\Inertia\\Vue\\": "src/" + } + }, "autoload-dev": { "psr-4": { "Marko\\InertiaVue\\Tests\\": "tests/" diff --git a/packages/inertia-vue/config/inertia-vue.php b/packages/inertia-vue/config/inertia-vue.php deleted file mode 100644 index 98439b74..00000000 --- a/packages/inertia-vue/config/inertia-vue.php +++ /dev/null @@ -1,9 +0,0 @@ - env('INERTIA_VUE_CLIENT_ENTRY', 'app/vue-web/resources/js/app.js'), - 'ssrEntry' => env('INERTIA_VUE_SSR_ENTRY', 'app/vue-web/resources/js/ssr.js'), - 'ssrBundle' => env('INERTIA_VUE_SSR_BUNDLE', 'bootstrap/ssr/vue/ssr.js'), -]; diff --git a/packages/inertia-vue/config/inertia.php b/packages/inertia-vue/config/inertia.php new file mode 100644 index 00000000..3cafcbb1 --- /dev/null +++ b/packages/inertia-vue/config/inertia.php @@ -0,0 +1,10 @@ + env('INERTIA_VUE_CLIENT_ENTRY', 'app/vue-web/resources/js/app.js'), + 'ssr' => [ + 'bundle' => env('INERTIA_VUE_SSR_BUNDLE', 'bootstrap/ssr/vue/ssr.js'), + ], +]; diff --git a/packages/inertia-vue/module.php b/packages/inertia-vue/module.php new file mode 100644 index 00000000..ab3ba738 --- /dev/null +++ b/packages/inertia-vue/module.php @@ -0,0 +1,12 @@ + [ + InertiaFrontendInterface::class => VueInertiaFrontend::class, + ], +]; diff --git a/packages/inertia-vue/src/VueInertiaFrontend.php b/packages/inertia-vue/src/VueInertiaFrontend.php new file mode 100644 index 00000000..9a3ce3c7 --- /dev/null +++ b/packages/inertia-vue/src/VueInertiaFrontend.php @@ -0,0 +1,15 @@ +toBe('app/vue-web/resources/js/app.js'); - expect($config['ssrEntry'])->toBe('app/vue-web/resources/js/ssr.js'); - expect($config['ssrBundle'])->toBe('bootstrap/ssr/vue/ssr.js'); +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['ssr']['bundle'])->toBe('bootstrap/ssr/vue/ssr.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 config-only marko module', function () { +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'))->toBeFalse() - ->and($composer['extra']['marko']['module'])->toBeTrue(); + expect(file_exists(dirname(__DIR__).'/module.php'))->toBeTrue() + ->and($composer['extra']['marko']['module'])->toBeTrue() + ->and($composer['autoload']['psr-4'])->toHaveKey('Marko\\Inertia\\Vue\\'); }); From 44cef753b6fb9c8bcb317e9f79a935dc922d48ab Mon Sep 17 00:00:00 2001 From: Mark Shust Date: Fri, 1 May 2026 20:44:35 -0400 Subject: [PATCH 4/4] refactor: align inertia-vue with sibling conventions and trim pseudo-config - Nest test namespace as Marko\Inertia\Vue\Tests\ to match every other Marko driver sibling (Marko\Cache\File\Tests\, Marko\Database\PgSql\Tests\) - Drop ssr.bundle config slot from companion and parent (no PHP consumer; Marko's SSR client only reads inertia.ssr.enabled and inertia.ssr.url) - Link the Inertia.js docs reference in the npm install note - Document the inertia.assetEntry overlay slot in the parent inertia docs Refs #17. Co-Authored-By: Paulo Carvalho Co-Authored-By: Claude Opus 4.7 (1M context) --- composer.json | 2 +- docs/src/content/docs/packages/inertia-vue.md | 6 +----- packages/inertia-vue/composer.json | 2 +- packages/inertia-vue/config/inertia.php | 3 --- packages/inertia-vue/tests/InertiaVueTest.php | 1 - 5 files changed, 3 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 1804ddf5..bc00825c 100644 --- a/composer.json +++ b/composer.json @@ -458,7 +458,7 @@ "Marko\\Health\\Tests\\": "packages/health/tests/", "Marko\\Inertia\\Tests\\": "packages/inertia/tests/", "Marko\\Inertia\\React\\Tests\\": "packages/inertia-react/tests/", - "Marko\\InertiaVue\\Tests\\": "packages/inertia-vue/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/", diff --git a/docs/src/content/docs/packages/inertia-vue.md b/docs/src/content/docs/packages/inertia-vue.md index 7f676df8..066d6b85 100644 --- a/docs/src/content/docs/packages/inertia-vue.md +++ b/docs/src/content/docs/packages/inertia-vue.md @@ -17,7 +17,7 @@ Install the matching frontend dependencies in your app: npm install @inertiajs/vue3 vue @vue/server-renderer @vitejs/plugin-vue vite ``` -Refer to the Inertia.js docs for currently supported versions of each frontend adapter. +Refer to the [Inertia.js docs](https://inertiajs.com/) for currently supported versions of each frontend adapter. ## Configuration @@ -26,16 +26,12 @@ 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'), - 'ssr' => [ - 'bundle' => env('INERTIA_VUE_SSR_BUNDLE', 'bootstrap/ssr/vue/ssr.js'), - ], ]; ``` | Key | Purpose | | --- | --- | | `assetEntry` | Vite entry used by browser-rendered Inertia responses. | -| `ssr.bundle` | Relative path to the built SSR bundle loaded by your SSR runner. | ## Usage diff --git a/packages/inertia-vue/composer.json b/packages/inertia-vue/composer.json index 1e3109c8..c69f6b73 100644 --- a/packages/inertia-vue/composer.json +++ b/packages/inertia-vue/composer.json @@ -17,7 +17,7 @@ }, "autoload-dev": { "psr-4": { - "Marko\\InertiaVue\\Tests\\": "tests/" + "Marko\\Inertia\\Vue\\Tests\\": "tests/" } }, "extra": { diff --git a/packages/inertia-vue/config/inertia.php b/packages/inertia-vue/config/inertia.php index 3cafcbb1..09e3cb90 100644 --- a/packages/inertia-vue/config/inertia.php +++ b/packages/inertia-vue/config/inertia.php @@ -4,7 +4,4 @@ return [ 'assetEntry' => env('INERTIA_VUE_CLIENT_ENTRY', 'app/vue-web/resources/js/app.js'), - 'ssr' => [ - 'bundle' => env('INERTIA_VUE_SSR_BUNDLE', 'bootstrap/ssr/vue/ssr.js'), - ], ]; diff --git a/packages/inertia-vue/tests/InertiaVueTest.php b/packages/inertia-vue/tests/InertiaVueTest.php index c8b67c53..ef6bbab1 100644 --- a/packages/inertia-vue/tests/InertiaVueTest.php +++ b/packages/inertia-vue/tests/InertiaVueTest.php @@ -9,7 +9,6 @@ $config = require dirname(__DIR__).'/config/inertia.php'; expect($config['assetEntry'])->toBe('app/vue-web/resources/js/app.js'); - expect($config['ssr']['bundle'])->toBe('bootstrap/ssr/vue/ssr.js'); expect($config)->not->toHaveKey('ssrEntry'); });