/
WebsiteSupport

DocsDeveloper guideBuild an add-on

Pages (Vue)

Your screens are Vue components in a browser bundle you ship as dist/addon.js. The system loads it before the first page mounts.

1 min read

How the bundle is loaded

On activation, dist/addon.js, addon-pages.js, addon.css and icon.svg are copied to public/build-addons/<slug>/ (app/Support/Addons/AddonInstaller.php:238-278). Every page then imports each installed add-on's bundle before Inertia mounts, with a version stamp from the files' hash so browsers never keep an old one (resources/js/app.js:121-143, app/Support/Addons/AddonManager.php:270-308). A bundle that fails to load is logged and skipped; the rest keeps working (resources/js/app.js:128-141).

What your bundle gets from the host

Do not bundle Vue or Inertia. Use the host's copies through window.OptiraVendor: vue, inertia, ui (including OptiraLayout and SettingsShell), and lib (format, menu, ui helpers, slots, form sections, date helpers) (resources/js/app.js:68-107, resources/js/lib/vendorUi.js:90).

Registering a page

Add your components to window.OptiraAddons.pages under '<slug>::<Name>'. Inertia looks there first (resources/js/app.js:367-375):

Object.assign(window.OptiraAddons.pages, { 'hello::Index': Index, 'hello::Settings': Settings });

Building with Vite

For real .vue files, build an IIFE with vue and @inertiajs/vue3 marked external and mapped to OptiraVendor.vue and OptiraVendor.inertia. Subscriptions shows the setup (app/Addons/Subscriptions/ui/vite.config.js, app/Addons/Subscriptions/ui/src/index.js:1-11). Run its own Tailwind pass, because core's stylesheet holds only the classes core uses (app/Support/Addons/AddonManager.php:51-57). Copy the output into dist/ and keep the build scripts out of the add-on folder, since the package refuses .sh files (see Folder layout).

Hooking into core screens

Besides pages, a bundle can add form sections, slots, form actions, stat buttons and view actions to core screens through window.OptiraAddons (resources/js/app.js:94-107).

See also