-
Notifications
You must be signed in to change notification settings - Fork 140
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
ESM build #41
Comments
That's great, thanks for doing this. When I created LJS I decided not to use modules in order to keep things as simple as possible. Generally I have not used modules that much, can you tell me more about why you prefer to use them for something like this? Would it be possible to to make the engine build system automatically spit out engine.all.module.js? Also, is the header actually necessary? It seems like it just needs a footer with all the missing get/set functions and the export line. I can update engine.bat file to combine all and the footer and spit out engine.all.module.js in addition to the other files. Does that sound good? |
I love modules, and have found them good for a few reasons:
I anticipate the developer experience for LittleJS with ESM will be:
No. I thought there might be some use for it later on, but I guess not.
Yes! I made the changes and made a PR: #42 Let me know what you think. |
+1 to make LittleJS modules-friendly. I'm using vite to build my stuff, and when it creates the release folder it skips adding the scripts that are not modules and modules not being used. Of course you can manually add the files to the distribution build but it's something you don't want to do everytime. I also use an app that makes it possible to use webpages as applications and it comes with a predefined set of commands that makes it impossible (I guess) to build the executable and add files manually right after. So yeah +1 overall 🦊 |
esm build now included! still needs work but this is a good path forward, thanks for your help and advice. |
Modules now fully supported and I added a demo that uses them! |
I recently made a game using LittleJS and overall had a great experience. But since I like to use ES modules, it was a little awkward using the little engine because it doesn't expose the variables/methods it uses.
I'm looking to build on the previous project, and I wanted to improve this experience so I did a proof of concept turning the
engine.all.js
file into a file that can be imported ESM-style. See code here: https://github.com/deathraygames/wisdom-of-the-ages/tree/main/src/little-engine-esm The way it works is that if you runlittle-builder.js
it will just append the three files together:little-header.js
,engine.all.js
(latest from node modules), andlittle-footer.js
. In the footer I'm exposing all the variables and methods, and had to add a few getter and setter methods. The resulting file islittle-engine-esm-build.all.js
.Work on the footer is not complete. To expand on this I would add get/set methods for all variables, and avoid exporting them directly. The downside of all of this is that makes the code somewhat larger: 177+ versus 172 KB. But to someone who loves ESM, that trade-off is worth it. Maybe someone has ideas of ways to make this smaller and/or to make the footer generation more automatic?
Would you like to have this kind of ESM build included in the LittleJS repo? If so I can fork and do a PR.
The text was updated successfully, but these errors were encountered: