Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide the loader as modern es6 module #541

Open
danimoh opened this issue Feb 14, 2020 · 2 comments
Open

Provide the loader as modern es6 module #541

danimoh opened this issue Feb 14, 2020 · 2 comments

Comments

@danimoh
Copy link
Member

danimoh commented Feb 14, 2020

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.

@sisou
Copy link
Member

sisou commented Feb 14, 2020

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

@danimoh
Copy link
Member Author

danimoh commented Feb 14, 2020

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants