<style> block. When your components need npm packages, imports between files, styles or Pinia stores, build them with Vite in your project and load the result into the administration.
How it works
- Your build is a separate bundle, loaded after the administration with the private admin assets.
- It does not bundle its own Vue, Pinia, lodash or moment. The imports are mapped to the copies the administration exposes on
window, so your components run in the same Vue app. - Every
.vuefile inresources/js/componentsis registered inwindow.crudadmin.componentsunder its file name, and becomes a global component. - PHP references the component by that name, for example
Group::component('SubscriptionBanner')or->component('EventsBuilder', 'lesson').
Publishing the scaffold
Install the packages and start the dev server:
npm run build writes the production bundle into public/build.
Loading the bundle
The scripts slot is rendered with the private admin assets, after the administration has loaded and the user is signed in. It uses the LaravelVite facade, so the dev server with hot reload is used while public/hot exists, and the built manifest otherwise.
resources/views/vendor/admin/slots/scripts.blade.php
input in vite.config.js.
Vite configuration
vite.config.js
- Externals. Do not remove
vueandpiniafrom the externals. A second copy of Vue breaks reactivity between your components and the admin models, and a second Pinia does not see the admin stores. - Auto imports. Vue, Vue Router and Pinia functions, and everything exported from
resources/js, are available without an import. Your own composables and stores work the same way. - Dev server port. When another Vite dev server of the project already uses port 5173, give the admin build its own port with
server.port, so both can run side by side.
Writing components
A built component uses the globals of the administration directly:getFreshModel(), getActiveModel(), Modal, Toast, useAxios(), the admin stores and the global components such as ModelRowsBuilder. See Vue app and Models in custom components.
resources/js/components/SubscriptionBanner.vue
pinia, so they are shared with the administration:
resources/js/store/subscription.js
resources/js/app.js is also the place for code that runs once the administration has loaded, for example loading your own data or opening a modal after a redirect.
resources/js/app.js