Maintaining a Library Compatible with Both Babylon.js Packages (ES6 and UMD)

I’m developing a library for Babylon.js and currently maintaining two separate repositories:

  1. Repository #1: Uses scoped packages (@babylonjs/core, etc.) for ES6 modules, deployed to NPM.
  2. Repository #2: Uses non-scoped packages (babylonjs, etc.) for NPM and also produces a UMD/CDN-hosted version.

This dual repository maintenance is becoming cumbersome. I’d like to know if there’s a recommended approach for developing a library that works with all these distribution methods, ideally from a single codebase.

Questions:

  1. Is there a recommended pattern for library authors to support both package types and CDN distribution?
  2. Could I use build-time configuration or conditional imports to target all three versions? (not sure this would work with peerDependencies)
  3. Are there any existing libraries that handle this well that I could reference?
  4. Is it advisable to focus on just one version (ES6) and provide migration instructions for UMD users?

Any guidance would be appreciated :slightly_smiling_face:

Edit:
Looking through the babylon repo, looks like this may be a part of the puzzle Babylon.js/packages/dev/buildTools/src/packageMapping.ts at master · BabylonJS/Babylon.js · GitHub

I solved this in a monorepo by using a pre-commit hook that syncs source files between packages. I maintain independent package.json files for ES6 (@babylonjs/core) and UMD (babylonjs) versions while keeping the actual ts code synchronized automatically. Only package-specific files like babylon.ts are excluded from syncing - this file has different imports in each package (importing from babylonjs in one package and from @babylonjs/core in the other).

While this works, it still feels like a hack.

3 Likes