Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Environment into viewData #10

Open
neilyoung opened this issue Dec 17, 2024 · 0 comments
Open

Environment into viewData #10

neilyoung opened this issue Dec 17, 2024 · 0 comments

Comments

@neilyoung
Copy link

I'm wondering if it would be possible to have the current APP_ENV in the app template in order to conditionally render different app.js (e.g. once from /dist, once from vite development server).

I could achieve that by patching your code (providing APP_ENV in the constructor and retrieving it on render). This allows me to do kind of this:

{{ define "inertia.tmpl" }}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="icon" type="image/x-icon" href="favicon.ico">
    </head>
    <body>
        <div id="app" data-page="{{ marshal .page }}"></div>
        {{ if eq .env "local" }}
        <script type="module" src="http://localhost:5173/resources/js/app.js"></script>
        {{ else }}
        <script type="module" src="/dist/app.js"></script>
        {{ end }}

        <h3> Environment {{ .env}} </h3>

    </body>
</html>
{{ end }}

Looks clumsy, but I found no other way so far. So the question is: Would there be one? I see, that the current Render puts it all into the JSON page data, which is fine. But I don't need it there for this special moment.

Sorry, if too stupid. If not, I would be happy to provide a small PR

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant