How to create a standalone command line tool by rescript?

I have created a simple cli tool written by rescript. I just published it to the npm respository, and i use npm i -g install [package] to install this tool. It failed while i was ran it in the command line, because some the dependencies of this tool were rescript packages, and it would not be compiled into .bs.js files while installing the tool, this caused dependencies not found error. Is there any way to fixed this problem?

There are two ways of installing something like this. The first is installing the source version of the package, for this you need to ensure that ReScript is in the dependencies of the package. The second is to install a distributed bundle which can be run without any dependencies. If you want to publish a CLI tool which can be used without any dependencies (except Node.js) then the latter option is the way to go.

So long story short, you will want to bundle/minify/etc. your tool into a single script that can be run directly from Node.

What if the dependencies contains a pacakge which is written by c++? The bundle tools can not bundle it.

Solved it by adding rescript into dependencies, and add the command rescript build -with-deps in the install scripts.

You can also define which folders and files should be published, so if you point them to the generated “dist” folder and add a prepublish script to build it it should work