Working port to Rollup

yikes man, master/Tools/Gulp/tasks/gulpTasks-librariesES6.js is a really scary place to hide top-level package details, isn’t it?

honestly that script hurts my brain, why can’t this just be a simple package.json script called “build”? and why are the tsc options hidden in these command line options in this obscure script?

shouldn’t the tsc options just be in the tsconfig.json?

the problem is, i can’t figure any good reason to justify this overwhelming complexity – why can’t it just be a simple "build": "tsc"?

it’s this kind of non-standard stuff and great complexity that makes me sigh and not want to contribute – we could update this to a really simple npm script and none of these details need to be hidden or confusing anymore – what do you think about factoring out complex gulp stuff entirely, and moving towards simple npm scripts?

We could only at the expense of breaking backward compatibility unfortunately.

The code is the same for both es6 and bundled so when we build we need to upgrade the imports in the code to either target import from babylonjs or import from “@babylonjs/core”

So unfortunately there are a couple of extra steps needed here.

For the same reason it means our tsconfig.json need to be dynamics which is not possible and in order to keep consistency cross lib we tried to use the same command vs having it copy pasted in every folder (materials/gui/loaders…) preventing to fix the issue only for one of them.

I agree that the build is complex but all the tooling is in place for contributing without having to know the build details.

The main question would then be why would you need to understand the full build system to contribute ?

launching npm start from tools/gulp should be sufficient to get started ?

I am all for improving this part is it helps people to contribute but what is the main issue to solve ? documenting the local dev process ? Hiding our build complexity for our releases only ? How would people like to develop locally ?

also and more importantly, would you want to develop at once with all the packages (core/gui/materials/postprocesses…) or more isolated ?

first, my friend, please let me say – i really don’t want to come off as rude or unconstructive – i am indeed criticizing the complexity of the build – however as you’ve already corrected me about, fantastic work has already been done to simplify the build, and to modernize babylon with es modules, and from what i can see, the resulting package looks great – and i really really appreciate the hard work that you and others have put into it

here i want to try to sell you on my vision of a future babylon that takes this progress to the next level

it’s a vision of a babylon codebase that is even simpler, but it might require breaking changes in order to accomplish it

We could only at the expense of breaking backward compatibility unfortunately.

i propose we simplify and modernize the codebase for @babylonjs/core@5

i can’t think of any breaking changes this would necessitate, but if there were any, i’d be in favor of ripping the bandaid off quickly, and taking babylon users into the future kicking and screaming :wink:

they’ll thank us later, and it’s what other cutting-edge package are already doing without much complaint from the community – plus we can introduce them to fantastic new workflows involving unpkg and the new pika bundling cdn

The code is the same for both es6 and bundled so when we build we need to upgrade the imports in the code to either target import from babylonjs or import from “@babylonjs/core”

i don’t understand, why does there need to be any import rewriting magic at all? i mean, it’s pretty easy to set up a typescript build and then use a bundler like rollup, with a couple of one-liner npm scripts – why can’t babylonjs be this simple, when other libraries like lit-element, preact, and many others on the cutting edge really are that simple?

So unfortunately there are a couple of extra steps needed here.

even babylon can have a simple build, we must believe!

i think the barriers to this goal are a thing of the past – modern libraries no longer have these problems, so they don’t need complex gulp tasks to solve them – what makes babylon different in this respect?

For the same reason it means our tsconfig.json need to be dynamics which is not possible and in order to keep consistency cross lib we tried to use the same command vs having it copy pasted in every folder (materials/gui/loaders…) preventing to fix the issue only for one of them.

this doesn’t make much sense to me, and actually sounds terrifyingly complex… i think this whole class of problems could be eliminated by making the codebase as simple as any other typescript library

all of this complexity should be replaced by a simple tsc npm one-liner, and a simple tsconfig.json

  • all of the typescript in src/ gets transpiled into dist/ – job done
  • additional one-liners can be added to make deprecated legacy bundles, like with rollup or whatever

i see an attempt to justify all of this complexity – the reasoning seems to be, that we need the complexity in order to produce a variety of bundles, or a variety of module formats, whatever – however, these days, i know that simple one-liner tools like tsc, rollup, webpack, etc, they can do all of this work without the complexity – especially since the best practice is not to supply a wide variety of formats or bundles, and instead, only provide the one true format – es modules

is there anything specific about babylon’s codebase that requires any more complexity than a simple one-liner combined with a single tsconfig.json?

it seems to me that for babylon, all of the barriers towards a simpler codebase are self-imposed for legacy-support reasons, and all of that legacy-support and the complexity it brings, should be discarded with the next major version of babylon, @babylonjs/core@5

we should all enjoy a simple babylon codebase, with a few simple npm scripts, and a simple tsconfig.json – and we can even still have all of the bundles and legacy module formats (umd) that we want

i want to understand what are the current perceived limitations toward this evolution, and what are the potential downsides to switching to a really simple build for @5?

i am interested to participate and contribute in this evolution, if you are, so please let me know what you think :slight_smile:

cheers friend

:wave: Chase

The main question would then be why would you need to understand the full build system to contribute?

the more i understand about a codebase, the easier work is

imagine i needed to change a typescript option… how on earth am i supposed to find the command line tsc options buried deep within that gulp task? i’ve already forgotten where to find it, and you just recently told me

also and more importantly, would you want to develop at once with all the packages (core/gui/materials/postprocesses…) or more isolated ?

ah, i see this is a monorepo situation – personally, i prefer one package.json per repository, but to each his own i suppose…

also, i’m looking at babylon’s codebase, and i don’t see where each subpackage is located

  • i’m looking for @babylonjs/core, and in the babylon repo, i’m not seeing babylonjs/core/ or babylonjs/src/core or anything like that?
  • i’d expect each package published under @babylonjs/ should have a corresponding location in the babylon codebase
  • also it freaks me out that the main package.json says the package name is babylonjs but the actual package name turns out to be @babylonjs/core – i think something needs to be done about that to save confusion

where does the code for @babylonjs/core reside? where is its package.json? i wish this was really, really obvious for newcomers

this has been some of my train of thought about this situation, and it’s these kinds of pain points and confusions that come up when a codebase is maintaining loads of legacy workflow stuff – everything becomes unclear/nonstandard/confusing and requires a full investigation – i still don’t know how the babylon sourcecode relates to its npm packages

i have a proposal for simplifying the codebase into a single npm package

since libraries in the future don’t need to provide bundles at all, there is no bundle-weight to consider – we can simply have all of babylon’s sourcecode in a single src directory, even core and other subpackages, and then everything can compile into a single dist directory – people can import whatever they need, no bundles involved, no penalty in terms of loading extra code in a bundle, you only get what you ask for

and if they want a bundle, they can bundle it – or ask pika and they will magically bundle it for you (lit-element doesn’t provide a bundle, but here’s a fresh one made just for you https://cdn.pika.dev/lit-element)

in this scenario, the simple package name babylonjs could be ressurrected and repurposed, so importing anything to do with babylon could look like:

// core stuff
import {Mesh} from "babylonjs/dist/core/mesh.js"

// gui stuff
import {GuiStuff} from "babylonjs/dist/gui/gui-stuff.js"

// other stuff
import {SomethingElse} from "babylonjs/dist/other/something-else.js"

when we stop thinking in terms of bundles, we suddenly can organize all of babylon’s sourcecode into a single src directory without any performance penalty to the users

and heck we can still provide a bundle for each “subarea”, for “legacy people”, and we can even provide UMD modules too

// include the whole core bundle
import * as BabylonCore from "babylonjs/dist/core/bundle.js"

// include a core module in UMD format
import {Mesh} from "babylonjs/dist-umd/core/mesh.js"

and we could use barrelsby to make indexes of each “subarea”, and make core/'s index the main module entrypoint, eg

// magically works :)
import {Mesh} from "babylonjs"

i think that’d be super cool and very easy to maintain and understand :sunglasses:

cheers!
:wave: Chase

I would love to simplify it a lot just for maintenance purpose for instance, and I totally appreciate your help on this :slight_smile:

Basically src is core but it would be easy to have core/src instead which might be more obvious.

We could supposedly do the opposite and have everything locally set to es6 and do our es5 magic somewhere else which sounds like a good idea anyway.

This would probably make everything clearer for new joiners. Now the main issues become the “satellites” library like materialsLibrary

Currently it can import from either Babylon or @babylonjs/core depending if we build es6 or umd bundle. How could we workaround this easily. Also Quid of the bundled .d.ts generation ?

You can have a read at Our Journey into the Module World. - Babylon.js - Medium for all the issues we are trying to workaround here.

Wow. In between leaving and arriving home from work this managed to grow considerably.
I welcome that; the more discussion and debate, the better.

As far as the size difference: I am using rollup-plugin-terser for minified builds. I can’t find out what Babylon is using now for minification, but I’m gonna go out on a limb and say using the latest minifier tool has something to do with the size difference. Still, you guys are right. It should be tested very extensively before becoming the default.

For both ES6, UMD, and TypeScript, just use something like the following for package.json:

"main": "babylonjs.gui.js",
"module": "babylon.gui.mjs",
"browser": "babylonjs.gui.js",
"types": "babylon.gui.module.d.ts"

ES6 tools (like webpack and rollup) will automatically use babylon.gui.mjs (and then minify it themselves). TypeScript will use babylon.gui.mjs or babylon.gui.js as appropriate and import babylon.gui.module.d.ts for either. .min.js files aren’t listed because they are ment for consumption by browsers, not tools.

You do NOT want something like import {Mesh} from "babylonjs/dist-umd/core/mesh.js" - Ask RsJS, it is a mess to maintain. You want to use ES6 modules to import specific classes (UMD does not support tree-shaking).

As far as the build system, here’s all the advantages so far:

  • Clear, concise, and understandable. Just open rollup.config.js and rollup-plugin-babylonjs.js, and you can understand the entire build system right then and there. Gulp build system requires understanding a few dozen files.
  • The Gulp build system requires installing Gulp globally, and then running npm inside ./Gulp/Tools. For rollup: Just run git clone https://github.com/BabylonJS/Babylon.js && cd Babylon.js && npm install && npm run build and you’ve built the entire Babylon.js code base right then and there. Much friendlier for new developers.
  • For why not use tsc to generate ES6: It’s not “why not generate UMD from webpack and ES6 using tsc?” It’s “Why not generate UMD, ES6, and DTS using just rollup?” And the answer to that is: it’s simpler. Plus, rollup is faster. And if I use @babel/preset-env we can even use ES2019 proposals like chaining. Far, far to much code still uses var instead of const/let.
  • The current build system requires writing shader intermediate files and then compiling them. Rollup uses a plugin so no files ever have to be written.
  • rollup.config.js is declarative. It’s easy to understand and change. Gulp has linting, building ES6, building UMD, building DTS, and much more all bundled together and each wrapped in Gulp-specific boilerplate.

Another reason for transitioning away from Gulp and to NPM scripts: tslint will be deprecated in 2019. So switching from tslint-in-gulp to running eslint by npm run lint` might be the smart solution.

My goal for this was specifically to help make it easier for newcomers to contribute to Babylon, by simplifying the process of building and testing their code.

@sebavan It’s all up to you what we do. You just tell me what changes I need to make, and I’ll do my best. Can you tell me what you meant by it not working in browser? When I <script src="./dist/rollup/babylonjs.max.js"></script> in a HTML file, BABYLON is defined and BABYLON.Engine works just fine. I’m looking into the other things.

If you try using the loader, it fails at the moment.

My point is I agree it is simpler and win 100k. Both systems are using terser (terser has been the default in Webpack since a while now) The minification setup is not the difference here the main size difference boils down to scope hoisting not being setup in our bundle.

About ES6, we do not want a new target as it is the case here with a bundled .mjs containing es6 code. We just want the exact output of tsc and I do not see why we should move from tsc to rollup for this part. It is adding an extra complexicity we do not need.

My wish would be a tsc only base system, but with that we can not bundle. Also the build system today does more than bundling it:

  • Checks circular dependencies
  • Lint (we will move to eslint soon)
  • Typedoc
  • Validate typedoc
  • host the build (smallest portion)
  • Generate our playground intellisense files
  • Generate our .d.ts bundled/module bundled/and ES6
  • Extra Validation for imports and other custom rules
  • handle the switch from our npm distribution
  • runs our tests (units/integration)
  • prepare local npm folder for publishing or local dev with npm link
  • tests our npm packages
  • ensures the es6 minimum package does not grow too much
  • Run our local dev server
  • Ensures a full compatibility between the generated map files and VsCode as it is our primary dev tool

We could rewrite all of it in npm only but at the end it does not simplify much aside of removing the gulp global command and adding a lot of new npm commands.

Based on all the feedback I understand that there is a need for simpler local build but would it be reasonable to have 2 different ways of building (fragmentation might actually be worse and debugging harder).

Replacing Webpack by rollup, does not change the issue, we still have a monorepo with complex build dependencies we need to handle. Building only core is simple and you can even today launch either tsc or webpack directly in the src directory but this is a tiny percentage of the full experience.

We could nevertheless migrate to win this extra 100k but we would still need something driving our scripts dependency (npm or gulp at the end is still code)

My main question is still the same, what are you trying to achieve whilst building locally ? and what dev workflow are you using ?

Currently we have all the tool in place to never need to build locally. Actually, today I only look at the CI result on my PRs, and I do all the rest locally in the localDevFolder. The full build is mainly intended for release not necessarily for daily development.

For me the biggest win would be to ensure that anybody feels OK to contribute but I wonder what dev process are you using like are you building copy pasting the output and testing on another website and so on ?

My goal is basically to delete the entire Tools/ directory, and to make sure that rollup.config.js and rollup-plugin-babylonjs.js are the only two files controlling the entire build. To make it so that linting, typedoc, intellisense, dts, uploading to NPM, running tests, and local dev server are all kicked off by simply running npm run <task>. At most, for only one or two of those tasks, there would be something like scripts/intellisense.js which would be a regular Node script so users could easily understand it.

By your own admission in Our Journey into the Module World, the entire build process involves an awful lot of hacking things together. I want to create a nice, simple elegant solution.

Some other things you brought up in that post:

  • Rollup does not explode the build process, even when building 23 different modules (plus maps and .d.ts) all at once, all within 3 minutes.
  • I sympathize with the pain you described. We have all felt that at some point. The pain of duct taping and hacking together a solution to just do what you want. You are right; that is hard and painful. But so far, porting to rollup has been fun. Just look at the two rollup files: so far, I have got down generate UMD, ES6, minified, .map, and .d.ts for every single Babylon module (including max), shaders, and externals. And most of it only took one or two days.

For ES6, try this:

// node --experimental-modules tmp.mjs
import { Engine } from './dist/rollup/babylonjs.mjs'
console.log(typeof Engine)

That proves the ES6 works in Node, and since Rollup automatically targets web browsers unless configured otherwise, that means it almost certainly works in web browsers (can’t test right now because modules only work served over HTTP).

You keep asking over and over why we don’t just use tsc for ES6. And my answer is this: “Do you prefer to use Webpack for UMD and TSC for ES6, or would you prefer to use Rollup for UMD and ES6 at the same time?”

And, while I’m not 100% sure about this, I think Rollup can actually support circular dependencies. As in, if myFunc1 in one.js import the named export myFunc2 from two.js, and myFunc2 uses named export myFunc3 from one.js, I think that will work.

My goal is to use npm run watch during development, and npm run build when it comes time to distribute. That’s actually what I do now (even though not complete yet). So localDevFolder will no longer even be needed (hopefully). I wish to make the build system as invisible as possible, to get it out of the users way. Right now, it’s front and center.

What I wish for Christmas is an easy to follow process to create js framework for browsers (targeting different flavors UMD, ES6, Native Browser ES6) with their attached artifacts (.map, .d.ts) directly from TypeScript.

This is exactly what Rollup does. It generates a UMD and ES6 bundle for all frameworks (including max), and it generates .map and .d.ts artifacts.

So basically, my benchmark for when I am done is: can I delete the entire Tools/ directory but still keep everything working.

in es6, we want to keep the file separated and not bundled as it is the case in @babylonjs/core to allow better tree shaking and code splitting to work efficiently for the users. Bundlind in a single .mjs does not address this issue, it is just a separate target.

I would prefer a bundler (parcel/rollup/webpack) for UMD and TSC for es6 as if in the future we could release an es6 only version just through typescript.

But the local dev folder helps us on a daily bases to troubleshoot using playground like code as it is the case when you launch http://localhost:1338/playground/index-local.html or http://localhost:1338/sandbox/index-local.html

The .d.ts files currently generated by rollup do not seem to work on your github repo.

I am more than happy to switch if I can see it working :slight_smile: as I said removing all the tools we had to develop would be a pleasure but we need to ensure we can still build in the same way.

currently we only use two commands so far:
npm start for watch and local run
npm run build for releases

@Symbitic

i really appreciate the effort and hard work and research you’re contributing to babylonjs, and i love these kinds of discussions – i think this discussion will bear fruit and lead to a much leaner and meaner babylonjs@5

For why not use tsc to generate ES6: It’s not “why not generate UMD from webpack and ES6 using tsc?” It’s “Why not generate UMD, ES6, and DTS using just rollup?” And the answer to that is: it’s simpler. Plus, rollup is faster.

tsc can generate the es modules, and generate the umd modules, and the .d.ts files — what do you think rollup is adding to the situation? only more complexity

You keep asking over and over why we don’t just use tsc for ES6. And my answer is this: “Do you prefer to use Webpack for UMD and TSC for ES6, or would you prefer to use Rollup for UMD and ES6 at the same time?”

i want to use tsc to do all of it. neither rollup nor webpack has any place in the library, and has nothing to add

  • es modules – tsc does it well
  • umd – tsc does it well
  • .d.ts – tsc does it best
  • there’s nothing else desirable that rollup can provide

what’s important, is that the users can then take our modules, and then use them with rollup or webpack in their own app’s build – otherwise they can use a convenient pika url to instantly get an optimized bundle from any module as an entrypoint – that’s a big evolution that isn’t just going to “go away”

with these emerging best practices, modern libraries don’t offer bundles, just the same as they don’t offer minification – these are optimization concerns that are best left to the consumers

many users are already using rollup/webpack/browserify or other bundlers in conjunction with minifiers in their own app’s build – it’s totally redundant for every modern library to also provide minified bundles – the user’s bundler will bundle and minify the code that has already been bundled and minified – it’s pointless

and for even more convenience, the user can grab an optimized pika bundle (pika is unpkg for bundles!) – or better yet, just use direct es modules for development convenience

in this new ecosystem, there’s no important reason to use any bundler, or any minifier, in any modern library’s codebase – rollup and webpack have nothing to add but the complexity in their own configuration files, and is best left for consumers to control

we’re already going to have one tsconfig.json, and in my opinion, that’s already more than enough complexity (but i love typescript and wouldn’t take that away!) – the last thing we need are more gulp/rollup/webpack configs floating around

You do NOT want something like import {Mesh} from "babylonjs/dist-umd/core/mesh.js" - Ask RsJS, it is a mess to maintain. You want to use ES6 modules to import specific classes (UMD does not support tree-shaking.

of course, i mean nobody should want to use umd for any reason – es modules is the sacred best practice of the future – however there’s nothing intrinsically wrong with supporting legacy systems in a deprecated way

@Symbitic – one thing i really agree with you strongly about, is that we should remove all of the gulp stuff and the entire Tools/ directory – babylon shouldn’t be so complicated as to necessitate a whole directory of “custom build tooling” – there should just be a simple handful of industry-standard one-liner npm scripts like all of the other modern libraries

i also agree that the current complexity of the babylonjs repository is a major obstacle in attracting contributors

@sebavan

[…] (terser has been the default in Webpack since a while now) […]

i can see that you folks are getting all caught up in the old bundling mindset – you’re still hung up trying to work out solutions for problems that no longer exist

i think it will take awhile for it to sink in, but let’s step back: bundling is outside the scope of a modern library – these days, users can use their own bundler, otherwise they can conveniently use a magic bundling cdn like pika’s – this means we’re finally in the era where a modern library author can simply supply the universal format, es modules, and leave out all of the complexity (that’s not lazy, that’s a best practice because it’s so simple!) – at this point i’m just evangelizing for the modern ecosystem, but people on the cutting edge like pika’s team has plenty of reading material on the subject of emerging best practices

that all being said, i think it’s reasonable to include the legacy entrypoints, like the bundles, deprecated but present for legacy users to keep using their familiar workflow unchanged – i do however, think that legacy support should be achieved through a few simple npm one-liners

now, i really want to address the perceived obstacles in taming babylon’s complexity:

  • Checks circular dependencies
    • replace with a simple test suite
  • Lint (we will move to eslint soon)
    • one-liner: npm run lint
  • Typedoc
    • one-liner: npm run docs
  • Validate typedoc
    • what validation? of docs? doesn’t make sense, discard this complexity
  • host the build (smallest portion)
    • what do you mean “host the build”? i’ve never heard of this, discard this
    • do you mean “deployment”? that’s a ci concern, or maybe an admin’s bash script
  • Generate our playground intellisense files
    • this is already handled by tsc, discard any custom handling here
  • Generate our .d.ts bundled/module bundled/and ES6
    • already handled by tsc, discard any custom handling here
  • Extra Validation for imports and other custom rules
    • simple typescript codebases don’t need this, discard it
    • non-standard validation is an anti-pattern, discard this complexity
  • handle the switch from our npm distribution
    • what is this switch? discard this complexity
  • runs our tests (units/integration)
    • one-liner: npm test
  • prepare local npm folder for publishing or local dev with npm link
    • discard this complexity, publish a simple package like other modern projects
    • discard any custom tooling around, expect devs to use standard practices
  • tests our npm packages
    • use a simple npm test one-liner, discard any custom tooling for this
  • ensures the es6 minimum package does not grow too much
    • there is no “bundle size” worth considering, everyone just uses the modules they need
    • otherwise they use an optimized bundle with treeshaking
    • we don’t live in a world where bundle/package size is a concern anymore, because we don’t ship bundles anymore
  • Run our local dev server
    • one-liner: npm run start – i suggest using the serve cli
  • Ensures a full compatibility between the generated map files and VsCode as it is our primary dev tool
    • i’m a vscode guy too – discard this complexity, tsc already does this

through all of that, i see perceived obstacles, but no actual obstacles – all of the perceived obstacles are from another era, and quickly disappear once you embrace modern best practice workflows

note: when i say “one-liner”, i don’t just mean that it takes one line to execute the command – i mean the whole command should be implemented in a single line.

for example, to start the dev server, we’d do npm start

the start npm script would be implemented with this one line: serve dist – this launches an http server for the dist directory – every script can and should be this simple – the compile script can simply run tsc – the docs script can simple run typedoc, etc – we don’t need big custom scripts for all of this, we can just use industry-standard tooling

finally a prepare script should run all of the smaller scripts, eg, using run-p from npm-run-all (a great little tool!) to run each script in parallel to make it run really really fast

"prepare": "run-p compile lint docs"

The full build is mainly intended for release not necessarily for daily development.

i really think it’s an anti-pattern to have a one build for local development and a different build for release

with the emerging best practices, there should be only one build – it’s the ideal build for both situations – and it runs really fast – and it’s super simple because it discards/outsources all of the complexity

i think this discussion will lead to a much more lean/simple/approachable babylon codebase

i am happy to contribute and help draw up a plan for a dead-simple babylon that everyone can understand and work on together

let me know what you folks think

:wave: Chase

That’s what I plan on doing: keeping those two commands, just run in root.

I know the .d.ts isn’t working yet. Still trying to fix.
I’m working on a way to launch http://localhost:1338/playground/index-local.html, and the other things too.

I seem to have misunderstood you.

The whole point of this is to create a single ES6 bundle, instead of realeasing 400 ES6 module files. Most tools would have a much harder time using 400 different files than one bundle, because package.json has "module": "babylon.mjs". I think that for big projects, a single bundle is what is recommended, because otherwise that would mean hundreds of network requests.

I’m not sure how having many different files would help tree shaking. Rollup already optimizes the tree to make shaking it as efficient as possible. My recommendation would be to no longer distribute ES6 versions of each file, but instead to distribute one .mjs file for each module.

But it’s your call. If you decide that it absolutely must still be distributed as different files, instead of a single module, then I’m probably going to abandon this. I will leave my work up for future reference.

I welcome any suggestions though.

@Symbitic

This is exactly what Rollup does . It generates a UMD and ES6 bundle for all frameworks (including max), and it generates .map and .d.ts artifacts.

that’s the problem – my argument is that fundamentally, bundling has no place in the future of modern library codebases – it’s a concern for the consumers, not the library authors – it’s nothing against rollup or bundling – it’s just not the right side of the fence to be using rollup

it’s possible we might use a nice rollup one-liner to create the legacy bundles, however, that’s an ugly deprecated wart that we should all want to forget

@sebavan

i want to point out that the existence of a “localDevFolder” really freaks me out, i’ve never heard of anything like that – i expect to run a build, run a static http server, and use all of the modules in the package “as-is” without any funky custom hacks going on

currently we only use two commands so far:
npm start for watch and local run
npm run build for releases

i propose these are the new top-level commands

  • npm install – installs deps and runs a full build (via “prepare”)
  • npm run watch – runs a server and incrementally builds any changes

we can accomplish this cleanly with all of the simplification i’ve been proposing

@chase-moskal and @Symbitic there is obviously something I am not understanding here probably due to some lack of knowledge around build tools.

It looks so much easier on how you present it and I am all for it. Could you fork the repo somewhere and fix the build stuff as you think is best ? I would really appreciate it as it would be a great contribution.

About the local dev folder, it is our way of copy pasting playground code locally to quickly iterate. There might for sure be a better solution as well and I would be all in.

1 Like

@Symbitic

The whole point of this is to create a single ES6 bundle, instead of realeasing 400 ES6 module files.

My recommendation would be to no longer distribute ES6 versions of each file, but instead to distribute one .mjs file for each module.

my friend, i love that we’re all having this discussion, but i want to point out that i think you have it exactly backwards

we actually do want to ship 400+ individual modules, and we don’t want to ship any bundles

let me try to illustrate this with examples

  • here’s lit-element.js
  • it’s made of a bunch of individual es modules
  • now look at this optimized tree-shaken bundle: https://cdn.pika.dev/lit-element
  • where did i get that bundle? not from lit-element, because they are a modern library, they don’t ship bundles, they only ship individual es modules
  • tools like the pika cdn can magically generate an optimized tree-shaken bundle out of any individual javascript module on the whole of npm
  • yes you read that right, it’s really that easy these days!

so in conclusion – modern packages only ship simple individual es modules – the reason is that it’s so easy for consumers to obtain optimized bundles, it’s nonsensical for library authors to be trying to implement it in, say, babylonjs

check this out

wait, that babylon core bundle isn’t working? that’s because babylon isn’t compatible with the new ecosystem, because it doesn’t implement these emerging best practices

folks, i propose we make babylonjs@5 really lean and mean, and let’s make it pika compatible :sunglasses:

cheers!

:wave: Chase

@sebavan, awesome, yes! especially now with your blessing, i will create a fork that we can discuss further

i’m really glad this has been a productive discussion, sometimes i’m afraid i’m too blunt and opinionated, so i’m really glad this didn’t turn defensive – i’m massively appreciative of the immense hard work you have put in to improve babylon’s codebase – i really love babylon, and this build stuff in particular is something i’m versed in, so this is how i’d like to give back and contribute – i’ll reach out to you once i’ve prepared a fork that we can review together, give me a couple weeks to carve out the time for this

@symbitic – thanks for your contributions in code and this discussion, i think you’re on the right track looking to simplify babylon’s build, and using npm/rollup certainly would yield a simpler alternative to the current system – however i see it as almost a coincidence at no fault of your own that the emerging best practice is to phase out optimization tools like rollup from library code

cheers friends, i’ll post a new thread when i’ve produce a fork to review

:wave: Chase

1 Like

perfect we ll be happy to test and see how it impacts both our release and daily dev experience

1 Like

As

  1. a sometime contributor
  2. very much a hobbyist
  3. someone who likes the instant gratification of Javascript
  4. an old dog not wanting to learn new tricks (ie typescript, webpack, bundles, etc. etc.)
  5. a very patient person

I do not have the expertise to comment on Rollup V Webpack V Anything else but perhaps a description of my experiences in coding for BJS may be a useful contribution.

First let me say I appreciate the reasons for using Typescript and having a system to check the submitted code and generate the various Javascript files and am happy to struggle with Typescript mainly by copying similar code and getting help when types clash.

Up to sometime last year I usually managed to get the build to work locally and even to use the localDev folder for playground testing. However I started to get errors in the build usually after building the inspector. Despite updating npm etc these errors remain. However in a way this was good for me and I settled into this approach.

  1. Add new typescript code for new classes or whatever.
  2. Check TSLint errors and correct.
  3. Build and get errors towards end of build.
  4. Check a new Babylon.max.js has been built (99% it does, the 1% is an TSLint error missed)
  5. Construct local HTML pages referencing new Babylon.max.js with a createScene and check results
  6. Correct any errors in Babylon.max.js using Javascript
  7. Run local HTML pages until no errors.
  8. Correct Typescript in src file
  9. Repeat 3 to 8 until no errors
  10. Add new Babylon.max.js and HTML pages to my github repo
  11. Create Netlify link to github
  12. PR with links to Netlify to show changes work

What would make my life easier is a TSLint type thing to check for missing comments, spaces etc and if none stopped at that point and a build that if checks passed just builds Babylon.max.js (and perhaps Babylon.min.js) and leaves it at that.

However I can see that having to maintain two different builds (one for local and one for local plus distribution) would be an issue.

Anything that makes building simpler, for a novice like me, would be appreciated and I look forward to trying out a new prototype build fork.

1 Like

Just for the record, I personally think it would be best to just distribute exactly 7 files for each module (.js, .map, .min.js, .min.js.map, .mjs, .mjs.map, .d.ts). Seems like the simplest solution. Vue actually uses something like this. But since this is not what the developers want, I have no reason to complete this.

I will no longer be developing this fork. I will leave it up as a reference for anyone who wishes.

@Symbitic, I have just push the experiment to the end. I wrapped the mjs bundle in an npm package and consumed it from webpack/rollup.

Unfortunately tree shaking is disable when using it and the entire bundle comes down. This is all related to the babylon side effects in place. This actually the same issue pushing us to target individual files.