You can easily build rescript files with deno now

With deno now supporting most npm package, I had to try rescript with deno.

Turns out this is all you need to have Deno install rescript and build. I’m really impressed that it all works as described.

  1. usual bsconfig.json
  2. deno.json
{
    "tasks": {
        "res:b": "deno run --allow-env --allow-read --allow-write --allow-run npm:rescript",
        "res:dev": "deno run --allow-env --allow-read --allow-write --allow-run npm:rescript build -w"
    }
}
  1. deno task res:b
10 Likes

Are you using vscode? I can’t get the ReScript vscode extension to work using Deno this way. I don’t get any code formatting or code hints. Code does build and run though.

Extension only seems to work if I do a traditional npm install and use an import map file pointing to the node_modules rescript directory.

No the vscode extension doesn’t work. I started looking into it.

The extension only looks for rescript in the local or global node modules. I’ll look into it and see if I can raise a PR that works with deno. It should just be a path addition right?

So there’s a quick workaround to have Deno create a node_modules directory.

deno run --node-modules-dir main.ts. Assuming main.ts is your entrypoint, it’ll create a node_modules folder. The extension now works. But it’d be a nice option to not run this additional cli option.

I created a github issue with some exploration. If @zth @cristianoc is open to this, maybe the extension can “natively” support deno.

Lol Deno is 1.5x faster. Build takes 9-10ms on Node and 6ms on Deno.

That did the trick, thanks!

After doing a clean and build, formatting and code hints are working!

1 Like

There shouldn’t be any difference in build time because it’s the rescript compiler doing the work. The difference could be in startup time of node vs Deno.

Yeah that could be it