Compile and use in ts project

Hi, I was wondering if its possible to build a library that can be used in a pure js project and if so what steps are needed?

What I would want is to build stuff in rescript and then use it in my pure js project without rescript as a dependency. An example is building api services, so skipping stuff like zod.

I have some 3rd party dependencies inside in bs-deps and when I generate js files the generated file imports from File.gen for example.

Do I need something specific to get it to work?

Thanks in advance.

Hey! I don’t think ReScript has a seamless story for building JS libraries.

Additional bundler features can make it possible, but the truth is that finding a good build tool for your library is still a challenge in the entire JS ecosystem.

Some related conv:

And I had a plan for this personally

But none of that is about ReScript. So I opened an issue to track all the improvements needed to solve this issue in purely ReScript, and called it “Library Mode”

Library mode includes everything about it like, improving basic interoperability with Js/Ts projects, generating .d.ts on the fly, publishing dual packages, etc.

It’s also the major milestone for v12.

Take a look and let me know if it’s close to what you want.

2 Likes

Before the library mode, my current recommendation is to use tshy as an additional build tool for genType’s .ts outputs.

1 Like