I built a library bundler called nanobundle that supports the imports/exports map in the package.json
.
imports/exports map is quite important when building libraries in ReScript because the ReScript compiler only builds a module spec at once.
You may need some bundler features to support both CJS/ESM at once. For example:
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./package.json": "./package.json"
},
"imports": {
"@rescript/std/lib/es6/": {
"import": "@rescript/std/lib/es6/",
"require": "@rescript/std/lib/js/"
}
},
9 Likes
zth
January 2, 2023, 8:30pm
2
That’s great! Do you have a write up or similar somewhere of a good approach for packaging a lib written in ReScript for multiple output formats etc? Essentially everything you need to think about when packaging a ReScript lib for consumption outside of ReScript. That would be quite valuable for the community to have I think.
1 Like
DZakh
January 3, 2023, 11:02am
3
Looks like the tool I wished for
I’ll try it out for rescript-struct and rescript-stdlib-vendorer and share feedback
I also have a draft of an article about creating a ReScript library for Js/Ts consumers. Will be a great addition if the tool works as I expect.
1 Like
DZakh
January 8, 2023, 2:40pm
4
Didn’t work for me The problem is with me using commonjs
output.
Could you file your issue to the nanobundle repo?
DZakh
January 8, 2023, 3:31pm
6
The nanobundle
worked fine. I’m just more of a specific case.
DZakh
April 26, 2023, 12:08pm
7
Here’s the logic I wanted to have:
committed 12:02PM - 26 Apr 23 UTC