HenriMorlaye

HenriMorlaye

Hi,
I was reading the VueJS documentation and then I thought about something:
What if a Phoenix template engine rendered .vue.eex files instead of .html.eex files ?
(.vue files are single file components including the html fragment (with the vue attributes), the script fragment with the vue viewmodel and the style css fragment.)

The template engine would render the vue component tree the same way .vue files are compiled in webpack, and phoenix would serve the compiled html to the client.

The magic would be that instead of writing html, we could write very reactive front-end code, using packaged components but without having to jump into the whole SPA thing.

I thought that a potential problem would be that .js and .css fragments are compiled on the fly, instead of preprocessed and bundled as it is currently the case in Phoenix. But if I am not mistaken, if each components’ js and css fragments are served as individual files instead of a concatenated file, then it would not be a problem on http/2 servers ?

Any thoughts ?

Showing Posts 1 to 8

kokolegorille

kokolegorille

It looks like You want to do server side rendering with vue.

I think it’s possible to put an intermediate node server that would interpret javascript and render html. Also in react, there is a render to string method, that helps doing SSR.

Otherwise, the Drab library can help You generate reactive frontend, from the server.

But I am not sure it would be easy for phoenix to take vue files, interpret js, and output html.

LostKobrakai

LostKobrakai

There are a few hurdles with your idea:

  • EEx won’t parse custom templating. It’s “Embedded Elixir”, which comes down to elixir code within tags within arbitrary text.

  • Phoenix can have other templating engines than eex, but it’s probably a lot of work to map vue templates to elixir code at compile time and your js bundle would still need the templates in js form for runtime updates of the markup. So besides a third party form of SSR (without hydration) it’s not really improving much.

  • Just compiling the templates for usage with the lighter vue runtime basically means the vue templates are compiled into js functions. That’s imo a clear concern of a js bundler and not elixir. It’s still js, which comes out at the end.

SSR with vue can probably be more smoothly implemented by using it’s new (v 2.5) V8 compatible renderer within the beam or an external node instance on the same server. This can execute the SSR part of rendering vue components natively.

HenriMorlaye

HenriMorlaye OP

I wasn’t thinking about SSR. More about building a Vue tree inline in the html template and sending it to the client. The client then initializes automatically a Vue instance on the html body.

Imagine for example returning this template:

<body>
  <h1>Your Birth Date Picker</h1>
  <datepicker current-date="<%= Date.utc_today %>">
    <p>Please, <%= @username %>, insert your birth date</p>
  </datepicker>
</body>

But the datepicker vue component would be built from a .vue template file.

LostKobrakai

LostKobrakai

Having custom html markup injected into components is already possible by using inline-templates or slots, so I don’t really get what you expect the .vue.eex file to accomplish over a .vue file bundled into your js assets.

HenriMorlaye

HenriMorlaye OP

Indeed, I have a similar setup already. I guess my “problem” is that some eex file renders a template containing an inline vue component, which is somewhat connected to a css and a js file somewhere in my assets. Reading the Vue doc I found the idea of single file components (the .vue file) interesting to solve this, thinking that the file in web/template could contain all the markup / logic / styling colocated.

aadii104

aadii104

@LostKobrakai thanks for the elaborated answer.
I have got a doubt from your statement (“SSR with vue can probably be more smoothly implemented by using it’s new (v 2.5) V8 compatible renderer within the beam or an external node instance on the same server.”) and actually I am looking solution for this.
Doubt is :- how can i make sure that the vue rendering and processing will done within the beam ? coz at last this could be a bottle neck.
please do share your comments and any follow-up article/ code sample to achieve same.
Thanks.

LostKobrakai

LostKobrakai

There are v8 implementations for erlang out there, but I’ve not used them so I cannot say anything about their quality. To use them with vue SSR you probably need to put the pieces together on your own. I’m not aware of anyone having done that already.

adesakin

adesakin

I truly wish we can have vue.eex.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews