A server bundle for executing JS on the server

I have a non-typical use case for executing JS on the server. We use react-email and react-pdf for generating emails and PDFs. Our current setup is a separate nodejs process with an HTTP API. Not productive.

Looking at Vaadin, I feel like all the pieces are there. Vaadin already compiles and bundles TS for Hilla. So, why not execute JS on the JVM using Graal or another JS engine.

Suppose Vaadin bundled frontend/server/* and placed it somewhere on the classpath. You would then load the script, call a function with args and get the result.

Doable?

I wouldn’t say that’s a typical use case; I think this is the first time I’ve heard of someone wanting to access the frontend bundle from the server. I know people have managed to get Vaadin to run as a GraalVM native image, but it’s not super common so far. Maybe start with a small proof of concept first and see how far you can get.

I think are correct in theory but I suspect things are more complicated in practice. The JS bundling system in Vaadin is built around the assumption of creating a single bundle and running it in the browser.

You could try splitting up this idea into two quite separate parts.

  1. Build the server-side bundle separately and then manually include it in the regular application and run it using Graal.
  2. Find a way of creating the bundle as part of the regular frontend build. This could be either with a completely separte build process triggered through e.g. frontend-maven-plugin or by customizing the Vaadin build by editing the vite.config.ts file in the application root.

I wouldn’t say that’s a typical use case

It’s non-typical, but it unlocks the entire JavaScript and React ecosystems from the JVM. Perhaps if made accessible and easy it would become “typical”.

You could try splitting up this idea into two quite separate parts.

I wouldn’t post on a Vaadin forum if I was going with option 1 :laughing:. I want to make use of the Vaadin build infrastructure including Typescript type generation. Will experiment with vite.config.ts and report back.