core-js icon indicating copy to clipboard operation
core-js copied to clipboard

Provide the loader as modern es6 module

Open danimoh opened this issue 4 years ago • 2 comments

Currently the web loader nimiq.js includes babel polyfills for old browsers and weighs 40kB which is pretty big compared to the web-offline package's 120kB. For people that build their apps using bundlers like webpack this is not optimal or needed, as the polyfills should be added in the bundling process, not be duplicated and only added if the user requested so. Webpack also can be set up to create a lagacy build with polyfills and a modern build without at the same time. Which version to use is then determined by the app at runtime.

For this reason I propose to add a nimiq.esm.js module version of the loader to our npm package which does not include any polyfills. I would also suggest to add an option to make loading the wasm optional as it is only required if the user intends to use cryptographic functions and can in that case be lazy loaded on demand.

danimoh avatar Feb 14 '20 00:02 danimoh

I don't think the Nimiq.js file is used when bundling with e.g. Webpack. The entry point of the core-web package is the esm build, which does not include any of that preloader stuff: https://github.com/nimiq/core-js/blob/master/packaging/npm-publish.sh#L23 https://github.com/nimiq/core-js/blob/master/gulpfile.js#L472-L487

sisou avatar Feb 14 '20 07:02 sisou

Yes, unless one specifically imports the loader to get lazy loading capabilities and the option to load the offline package. This would be the preferable approach over bundling the whole esm package. The loader module could even be defined as module entry point in package.json (but one would need to also tweak the types).

danimoh avatar Feb 14 '20 16:02 danimoh