decimal.js icon indicating copy to clipboard operation
decimal.js copied to clipboard

Tree Shaking

Open jacobp100 opened this issue 5 years ago • 16 comments

What are your thoughts on making all functions ES6 exports (like add etc), then providing a 'lite' constructor with no functions defined on the prototype or as static functions constructor? This would mean people could use the exported functions directly and can tree shake.

My project uses ReScript (/ReasonML), so I just write bindings to whatever the exports are.

In the app, the calculations are done in a web worker, so pretty much requires the whole of this library. However, once calculated, the results are sent back to the client, but the only functionality I need from this library is toString.

Having this library be tree-shakable would significantly reduce the size of my client file.

jacobp100 avatar Oct 23 '20 11:10 jacobp100

Thanks for the offer! I can handle doing this myself - I just wanted to know if you were interested in having it in the library. I'll aim make a copy of this library with the fix in the project I mentioned. You're welcome to copy it back if you want.

jacobp100 avatar Oct 24 '20 20:10 jacobp100

My work is over at https://github.com/jacobp100/technicalc-calculator/blob/master/decimal

Still in the process of getting all the tests to pass - but a few of the suites are passing already

I get a 15kb decrease minified. I noticed function names get minified now too. But also some of that reduction comes from reducing the precision of pi and ln10

jacobp100 avatar Oct 24 '20 22:10 jacobp100

I'm committed to keeping this library ES3 compatible, but I'll take a look. It's a good idea.

MikeMcl avatar Oct 25 '20 18:10 MikeMcl

Have you looked into adding build tools to this? It should be possible to write just one version (ES3 but with ES6 imports/exports), then produce an ES3-only bundle. That's something I could help with if you need!

jacobp100 avatar Oct 25 '20 22:10 jacobp100

Yes, that has been considered, but at the moment I prefer to just include a separate ES module file, decimal.mjs.

MikeMcl avatar Oct 26 '20 17:10 MikeMcl

I'm committed to keeping this library ES3 compatible, but I'll take a look. It's a good idea.

ES5 is supported everywhere now, including Internet Explorer which is like 10 years old. You do not need to support anything below that. If someone's browser does not support ES5 (or even ES6 now) then that isn't our issuse.

jakub791 avatar Sep 13 '22 18:09 jakub791

Yes, that has been considered, but at the moment I prefer to just include a separate ES module file, decimal.mjs.

Why does it use ES3 compatible syntax? Modules were added in ES6.

jakub791 avatar Sep 13 '22 18:09 jakub791