ES6 Without a bundler?

Hi! Just starting a new BJS project. I’m excited to checkout v4 and ES6 modules, but I have no plans to use a bundler. I’m trying to import something as simple as the Engine and Scene, but it fails when trying to import “tslib” (which I’m assuming is related to Typescript) because it’s not specified where that is. Is what I’m doing possible, or should I just avoid the ES6 modules?

1 Like

pinging @sebavan

If you intend to use directly in the browser the Bundled cdn version would be the easiest: https://preview.babylonjs.com/babylon.js

tslib adds all the code for TS features not supported by ES5 like for instance inheritance and so on.

Gotcha, thanks. While I would prefer to use the individual modules, I totally understand that you can’t please everyone. I did try a few things out when waiting for an answer - FYI, Pika seems to work pretty well for Babylon as is. Like I said, I’d prefer to import the modules, but with Pika, I can at least import the whole of Babylon as one module, so that’s a decent middle ground.

i wonder if you could workaround the tslib dependency ? As it is the only problematic one i guess?

I would assume its the only problematic one, it certainly looks like it - but then I don’t know what I’d find if it wasn’t a roadblock. The only thing that comes to mind as a workaround would be to potentially use import maps, but while I think they are finally shipped in Chrome, no other browser will have it for awhile - though it might fit my use case, because I don’t bundle in dev, but do bundle when releasing. In any event, it’s not a dealbreaker for me. Its more a nice to have because it creates a lot more natural transparency on what goes into Babylon and what I’m using.

I’m revisiting this issue today - and wanted to comment that I was a bit out of sync on the latest dev practices without a bundler. Bare module imports seem to be a best practice, but they don’t work with a dumb http-server like I tended to use.

Instead, using ES dev server | open-wc with Babylon ES6 imports seem to be working great!

1 Like

Thanks for link.

We have similar requirements.

It is actually similar to our local dev server adding .js and following npm modules when needed :slight_smile: