W icon indicating copy to clipboard operation
W copied to clipboard

Create an ESM build of the library so it can be imported

Open Lukenickerson opened this issue 2 years ago • 3 comments

Background

ESM (modules) are the future; they let developers handle dependencies without polluting the window scope.

Improvements

  • Create a w.esm.js build that uses export default W

Challenges

Can this be done in a way that...

  • doesn't increase the final build of a game?
  • uses the same source file (so there aren't two divergent main js files)?

Lukenickerson avatar Feb 03 '24 14:02 Lukenickerson

Hi and thank you for your suggestion. Can you please create a branch with an implementation that looks like what you propose here? I'm curious to see how it would look like and how to use it in a JS game. If it doesn't add too many bytes to the zip, it could replace the main version.

xem avatar Feb 03 '24 18:02 xem

Here's a working version of an ESM build: https://github.com/rocket-boots/W/blob/057c2786ff92a230c7b7877436954ae95b0a5e03/w.esm.js#L4 I'm working on an implementation in a game.

Lines changed are:

  • 4, 5, 6 - Needed to define these
  • 131 - fix from #23
  • 472 - cheap way to define AB and BC
  • 635 - the export

@xem -- Do you have the process of creating the zip documented? Then I could do a build and compare sizes.

Lukenickerson avatar Feb 06 '24 04:02 Lukenickerson

sorry, it was long ago and I don't remember it in detail but I'm quite sure I used Terser (https://try.terser.org/) to minify and ECT to optimize the zip (https://github.com/fhanau/Efficient-Compression-Tool) with a command like ./ect.exe -9 -zip ./W.zip

xem avatar Feb 06 '24 07:02 xem