Run single .res file

Hello everyone,

I have a quick question: Can ReScript run individual .res files? I’m currently prototyping a CLI application and exploring alternatives to TypeScript.

I’m still getting familiar with the JavaScript/TypeScript ecosystem and wanted to try something different. I’ve ruled out CoffeeScript (as it’s outdated) and Civet (which feels messy), but I really like ReScript’s syntax.

How can I achieve this? Any guidance would be appreciated!

3 Likes

Hello Gabriel,

Can you give more details about what you’re trying to achieve? There’s no built-in command to directly compile and execute rescript code but you can decompose this, run a command that’d compile a single file and then send it to your favorite execution environment, for example:

bsc -e 'Js.log("hello world!")' | node // prints: hello world!

But manipulating the compiler directly is definitely not handy, so I’d still recommend going the easier way of using the rescript or rewatch builder and point your execution environment to your compiled index file.

And yes, using ReScript to write a CLI can be very nice! Don’t hesitate if you have more questions!

This would be a really cool feature, at least at a glance. I do think we’d need to do some analysis on how this would work in different cases though - what about if you have dependencies that needs building, and so on. But, definitely interesting to explore.

3 Likes