Bun.js compatible with Rescript?

I would like to know if https://bun.sh is compatible with rescript. Has anyone here already tried it?

1 Like

It’s an interesting project. It can take on the responsibilities of bundler and test runner, so a ReScript template with bun can potentially let go of dependencies like esbuild/vite, jest etc. Let me try to play with bun this weekend and I can report my observations. Any specific thing you are looking for?

1 Like

I’m working on a mini framework for using ReScript with Htmx, and I’m using Bun as the backing tech. So I’m doing and have done some work on binding to Bun. Some more info: https://twitter.com/___zth___/status/1699126567849349425

I’m getting pretty close to open sourcing an initial version of that mini framework. Maybe the Bun part could be broken out to a rescript-bun package and we could work together on covering the full API in the bindings.

12 Likes

Since Bun does a lot of things, I think you can have many “is it compatible” questions. As in, can it be used as a package manager/task runner? A test runner? A bundler?

I use rescript with Next.js, I guess that is a blocker for bun

From what Jared said, they landed support for Next.js pages directory in Bun 1.0.

3 Likes

When I tried it worked fine up to some node apis they had not implemented. Otherwise it is a JS runtime so it seems like there should be no major rescript conflicts.

ymmv
A

Hey, can’t wait until you release this library. I’m playing around with vanjs, but I’m not satisfied with my bindings.

let make = props =>
  tag(
    "div",
    {},
    [Header.make({router: props.router}), tag("h1", {class: Styles.title}, [string("Home")])],
  )

So I’m wondering how you can use jsx and replace the generated react code with htmx stuff. Will it be replaced by the bun bundler?

The performance improvements that bun brings especially to websockets makes me want to build Phoenix LiveView like experience in ReScript. However I am inexperienced with building tools. Any pointers on where to get started hacking on the apis, just like @dkirchhof asked.

The bundler doesn’t accept aliases like in esbuild :frowning:

Which luckily doesn’t matter for ReScript, right? :grin:

Well, I want to replace import * as JsxRuntime from "react/jsx-runtime"; with something like import * as JsxRuntime from "./src/bindings/Van.mjs";

Unfortunately you can’t specify the jsxFactory or whatever in rescript/react.

Okay, bun can also “install” file modules.

bun add ./src/van-react just works :slight_smile:

Now I can use

let make = props =>
  <div>
    <Header router=props.router />
    <h1 className=Styles.title> {Van.string("home")} </h1>
  </div>

instead of

let make = props =>
  tag(
    "div",
    {},
    [Header.make({router: props.router}), tag("h1", {class: Styles.title}, [string("Home")])],
  )
4 Likes

As a follow up here, I will be releasing an initial version of rescript-bun very soon (within days).

@dkirchhof very curious about your experimentation with van-js. Do you have a repo or something to share?

5 Likes

:eyes:ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

Unfortunately I haven’t had enough time, but will continue the experiment next week.

After working with react for many years I was unhappy with some conceptual things.
For example: components in a list wouldn’t remember local state. So you have to save local states in the parent component.
Maybe a custom list component could fix this issue. I will try :upside_down_face: