One possible solution is to use Inertia's share method to share data between packages. You can define a shared data object in your main Inertia app, and then extend it in each package as needed. This way, you can reuse components and pages without having to recompile assets.
Here's an example of how you could set this up:
- In your main Inertia app, define a shared data object in your
app.blade.phpfile:
<!DOCTYPE html>
<html>
<head>
<!-- ... -->
</head>
<body>
@inertia
<script>
// Define shared data object
const sharedData = {
// Add any common data here
};
// Share data with Inertia
Inertia.share(sharedData);
</script>
</body>
</html>
- In your package, extend the shared data object in your
ServiceProvider:
public function boot()
{
// Extend shared data object
Inertia::share('users', function () {
return User::all();
});
}
- Use the shared data in your package's Vue components:
<template>
<div>
<h1>Users</h1>
<ul>
<li v-for="user in $page.users" :key="user.id">
{{ user.name }}
</li>
</ul>
</div>
</template>
<script>
export default {
// ...
};
</script>
Note that this is just one possible solution, and there may be other ways to achieve your goal depending on your specific requirements.