uber / h3-js

h3-js provides a JavaScript version of H3, a hexagon-based geospatial indexing system.
https://uber.github.io/h3
Apache License 2.0
867 stars 78 forks source link

h3-js is not tree-shakeable #150

Closed istarkov closed 2 years ago

istarkov commented 2 years ago

As of now minimal bundle size I see with importing only single method like import {latLngToCell} from 'h3-js' is like 140Kb+

The issue that generated esm in h3-js looks like

var libh3 = (function (libh3) {
!!!!!!!!!!! MOST CODE HERE !!!!!!!!!!!
})({})

...

function anyExportedFn(…) {
  libh3.callSomething()
}

...

export { anyExportedFn, ...}

So the most generated code are inside var libh3 = (function (libh3) { But nor rollup not webpack can tree shake code inside functions.

Would you mind to omit this init code from generator for esm to make it more tree shaking friendly?

dfellis commented 2 years ago

This is autogenerated by emscripten transpiling the H3 C library to Javascript. There is no way to accomplish what you want.

istarkov commented 2 years ago

Im pretty sure I can, it doesnt look like a big deal to convert generated function into module with exports and then bundle es module. Will you accept such PR?

nrabinowitz commented 2 years ago

We'd definitely accept PRs that improve the build!

If you're post-processing the build, this might not be relevant, but I thought it would be worth mentioning:

We're at least one major version behind on emscripten, this is something I've been meaning to improve. If you're going to look at the emscripten build, please: