Coder Social home page Coder Social logo

ESM build about littlejs HOT 5 CLOSED

killedbyapixel avatar killedbyapixel commented on May 18, 2024
ESM build

from littlejs.

Comments (5)

KilledByAPixel avatar KilledByAPixel commented on May 18, 2024

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?

from littlejs.

Lukenickerson avatar Lukenickerson commented on May 18, 2024

I love modules, and have found them good for a few reasons:

  • Avoids polluting the global namespace. Import/export makes it very clear where dependencies are coming from when you open a file.
  • Along those lines, since I usually use linting (ESLint extension) on my js files to check syntax, having no globals helps.
  • No need to modify HTML <script> tags to bring in new modules; just import them in your js.

I anticipate the developer experience for LittleJS with ESM will be:

  1. Make a new project (npm init, add html and js files)
  2. Run npm i littlejsengine
  3. Use import * as engine from 'littlejsengine'; (or some subset of methods, e.g., import { engineInit } from 'littlejsengine';) in their js.
  4. Do some build process

Also, is the header actually necessary?

No. I thought there might be some use for it later on, but I guess not.

Does that sound good?

Yes! I made the changes and made a PR: #42 Let me know what you think.

from littlejs.

LeFede avatar LeFede commented on May 18, 2024

+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 🦊

from littlejs.

KilledByAPixel avatar KilledByAPixel commented on May 18, 2024

esm build now included! still needs work but this is a good path forward, thanks for your help and advice.

from littlejs.

KilledByAPixel avatar KilledByAPixel commented on May 18, 2024

Modules now fully supported and I added a demo that uses them!

https://killedbyapixel.github.io/LittleJS/examples/module/

from littlejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.