reach-sh / reach-lang

Reach: The Safest and Smartest DApp Programming Language
https://www.reach.sh
Apache License 2.0
581 stars 167 forks source link

Add `exports` field to package.json in stdlib #1561

Closed Gungy2 closed 1 year ago

Gungy2 commented 1 year ago

By adding a separate entrypoint /browser for the library, we make it much easier for the users to import the library in a browser, like so: @reach-sh/stdlib/browser.

Summary

This would address #152, #1316 and #1560, by using the library like so: import { ... } from "@reach-sh/stdlib/browser. In the current implementation there is the field "browser" that points to the right entrypoint, but that is not usually supported by default in most bundlers. Moreover, it does not work at all if used with Typescript, since the right types are not exposed.

Probably, documentation will need to be updated, I am also willing to do that if pointed in the right direction. Thank you for taking the time to review this!

jeapostrophe commented 1 year ago

Thanks. I'd add the docs here:

https://github.com/reach-sh/reach-lang/blob/master/docs/src/frontend/index.md?plain=1#L23

In something like


:::note
If you have problems with JavaScript bundlers in your browser, you can instead require from `@reach-sh/stdlib/browser`.
:::
jeapostrophe commented 1 year ago

I don't really have a good way of testing... I'm assuming it is working for you?

Gungy2 commented 1 year ago

I don't really have a good way of testing... I'm assuming it is working for you?

Yes, I tested it locally. It is as easy as creating a skeleton Webpack 5 or Vite project, importing the library and logging the returned object. If everything is correct, it should build with no issues.

jeapostrophe commented 1 year ago

Thank you so much!