Hello :kotlin: friends, What if Node were more th...
# build-tools
s
Hello K friends, What if Node were more than just JS? To celebrate the new year, I am pleased to share a new project called Elide, a new server runtime, like Node or Deno, but polyglot, written in Kotlin and based on GraalVM. We are in alpha and very open to early feedback and contributions for anyone interested, over in #framework-elide 🥳 You can do wild things with it, like fast React SSR in Micronaut or Spring. Guest language support is starting with JS, but there are plans to integrate other languages like Python, Ruby, and Rust/Go/etc. via LLVM. Of course,
native-image
is supported out of the box. • 🚀 Trying it out
Copy code
curl -sSL --tlsv1.2 dl.elide.dev/cli/install.sh | bash -s -
👆 the one liner works on Darwin (amd64/arm64), and Linux (amd64) so far.
If you prefer NPX:
Copy code
npx @elide-dev/elide@alpha shell
K Building Kotlin apps with it • Elide can be used as a plain library with a regular Micronaut server, and Ktor support is on the way. There are Maven artifacts in a custom repository which is easy to use during the alpha; you can see a sample here. • G Gradle plugin You can easily install the Gradle plugin to build your frontend assets and your Kotlin/JS, and package it into your server binary. It will handle building for SSR and CSR both, so you can easily switch between browser rendering modes. Check it out here. Maven and Bazel support are planned. • 🖥️ Using the shell
elide shell
drops you into a shell just like Node (see attached screenshot), the difference being the
URL
class we're using here is implemented in Kotlin, backed by the road-tested power of Micronaut, KotlinX, Netty, and the Java standard library. It has simply been adapted for use in JavaScript, according to the WhatWG URL Spec. • js Use Kotlin/JS or regular Node stack Elide packages and consumes your JS/TS with built-in support for
esbuild
, so you can use a standard Node toolchain or the Kotlin/JS stack. • 💨 Super fast React SSR Because Elide is basically Kotlin with a super-fast JS runtime attached, it can do JS SSR without leaving the JVM. This can soon be drop-in compatible with many React apps. You can see a live sample here to confirm it is fast and server-rendered. The code for that sample is pasted below to show how simple it is to call back and forth between Kotlin and your React app:
Copy code
@Page class Index : PageWithProps<YourProps>(YourProps.serializer()) {

    // Serve React SSR.
    @Get("/") suspend fun indexPage(request: HttpRequest<*>) = ssr(request) {    // 1: tell the server we're going to do SSR for this request
      head {
        title { +"Hello, Elide!" }
        stylesheet("/styles/base.css")
        stylesheet("/styles/main.css")
        script("/scripts/ui.js", defer = true)   // <-- 2: serve the CSR bundle so it can hydrate the react SSR response
      }
      body {
        injectSSR(this@Index, request)    // <-- 3: execute the JS VM to produce the SSR response, and splice it into the server response
      }
    }

}
🐙 Contributors needed The future of software is much more polyglot than today's paradigm: developers love to fight about frameworks, but at the end of the day, we're all writing code, and eliminating barriers between languages means easier collaboration and more value for all of us. It shouldn't be a Node vs. The World or a Rust vs. The World argument; we should get to pick and pull the best code we want from anywhere and use it to build our apps, especially from a multi-platform language like Kotlin. This runtime and framework are designed for that future. *If you agree, join us and make a dent in the universe*; you'll have a chance to be impactful and shape a brave new idea from the ground up. • 🙏 Thank you We chose Kotlin because of the fantastic community. 2023 will be a massive year for Kotlin, and we think that betting the farm on it is reasonable and smart. We are super excited about what JetBrains and Kotlin have in store for us with K2, context receivers, value classes... just so much to look forward to. Cheers and happy new year, Kotlin devs, K sam Slack Conversation