Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sirhxalot's avatar

Inertia.js load compiled pages from package.

Hi Folks!

I would like to build multiple packages which each contains their own pages. My Goal is to have one package that contains the Inertia App including the common pages e.g. the homepage, authentication... Other packages should extend the app with new pages (those pages may already be compiled within the package). Lets say I have a package that is responsible to list all users on a page. My goal is to install the package with the app and than the user package but without re-compiling the assets. Is there a way that these Vue pages & components can be reused?

The common approach is to publish the resources and compile them to the assets. But I would like a solution where I don't need to recompile the assets.

Thank you in advance for any sugesstions.

0 likes
2 replies
LaryAI's avatar
Level 58

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:

  1. In your main Inertia app, define a shared data object in your app.blade.php file:
<!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>
  1. 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();
    });
}
  1. 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.

sirhxalot's avatar

@LaryAI Wow that AI - is amazing!!! But I need to know how can I load Vue pages into an inertia app which are already compiled?

1 like

Please or to participate in this conversation.