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

Add ESM installation method

Open TomasHubelbauer opened this issue 5 years ago • 2 comments

Hi! I really like UZIP.js, thanks for making it! I used to just drop it in my project and call it a day, but recently I've been really getting into ESM (ES Modules - using import and export to refer to other scripts). This is not to be confused with CJS, AMD and other import/export solutions which require compilers and bundlers. ESM is a browser standard and can be used from plain JavaScript. I decided to make UZIP.js available as an ESM module so that I and other people can use it this modern way.

In this PR I contribute an installation method using my ESM module to the readme. The module is automatically updated daily so it will automatically contain any new changes you make in UZIP.js without needing anyone to manually update it. This should save you the influx of issues requesting you update the ESM version like we can see with the NPM version uploaded once by someone else and then not updated anymore.

Hope you like this and all the best!

TomasHubelbauer avatar Aug 27 '20 16:08 TomasHubelbauer

Currently, no browsers truly implement ES Modules, so a transpiler like Babel converts ESM exports to CommonJS before bundling. Therefore there is no difference between the uzip NPM package and the linked repo. The only reason ESM is useful over CommonJS is for tree shaking, but UZIP uses a singular global object containing all of its internal methods, and methods inside objects cannot be tree shaken. Therefore, IMO adding support for ES Modules is not particularly useful.

EDIT: What I said above still applies for build tooling, but importing directly from the browser with ES Modules is now actually possible, so this would be a useful addition.

101arrowz avatar Aug 29 '20 01:08 101arrowz

I am using ESM in Safari, Firefox, Chrome and Edge in my plain Javascript projects daily. Not sure what you mean about the lack of support. Can you elaborate? Bundling and tree shaking IMO is beside the point here as I'm specifically using ESM to avoid needing to use any bundler or compiler. I write plain JS, save and reload. ESM is useful today.

Edit: I believe I still address your post even when edited, the main point being that this is specifically to support scenarios where additional web dev tooling is not used, plain JS is.

TomasHubelbauer avatar Aug 29 '20 04:08 TomasHubelbauer