fable-compiler / fable-compiler.github.io

Fable web site
https://fable.io
23 stars 64 forks source link

Blogpost Siren - Using Fable to create libraries for multiple languages #194

Open Freymaurer opened 2 months ago

Freymaurer commented 2 months ago

Hey, so i spent some time on a hobby project, in which i used Fable to create a library i published for python, js (+types), f# and c#.

In addition i wrote a blogpost about it on the issues i encountered, possible solutions and more.

If you are interested have a look here.

ncave commented 2 months ago

@Freymaurer Nice blogpost!

A small note, the default behavior of not attaching members to the class for JS/TS is done not just to allow member overloads, but mainly to allow the members to be tree-shaken by bundlers (if not used), and thus minimize bundle size.

Also, since interface implementation members are attached by default, implementing an interface would be another way to keep the members from being mangled and detached (although this doesn't work for static interface members yet, unless they have a default implementation).

Freymaurer commented 2 months ago

That makes sense! Is there a way to allow tree shaking with attached members?

Thanks for the input!

ncave commented 2 months ago

@Freymaurer

Is there a way to allow tree shaking with attached members?

It was not possible in the past, that's why the default detached member behavior in Fable is like that. (e.g. from an old rollup article, "It doesn’t currently remove things like unused methods from objects that are used").

But things might have changed, you may have to check your bundler's documentation.

MangelMaxime commented 2 months ago

@Freymaurer

Really interesting blog post, and can serve as a basis if others want to explore use Fable and generating code to consume from Native languages.

Great job 👍