Tree shaking when importing from @babylonjs/core

Has anyone looked at implementing a plugin similar to babel-plugin-lodash but for Babylon?

This would let you import from @babylonjs/core while allowing for tree shaking, so you don’t have to think about which file is the right one to import from.

I tried using babel-plugin-direct-import to do this for me automatically, but it didn’t work. I’m guessing it doesn’t follow export * as and all the root-level exports are themselves export * as.

This was the config I used:

[
        "babel-plugin-direct-import",
        {
          modules: [
            "@babylonjs/core",
            "@babylonjs/gui",
            "@babylonjs/inspector",
            "@babylonjs/loaders",
            "@babylonjs/materials",
            "@babylonjs/procedural-textures",
            "@babylonjs/serializers",
          ],
        },
      ],

There’s probably a way to auto-generate the list of files to import from based on the paths in the export * as from the index files in @babylonjs/core (i.e. flatten it). From there, we could have a plugin that rewrites the imports for us.

I might be able to do this when I work on reducing the bundle size in my game

That would be a nice feature to have, but we don’t have it in our pipeline at the moment.

I assume direct-import doesn’t work because of the legacy path support, but this is just an assumption.

Using VSCode, i actually always get the right path for the import, so i guess it never bothered me. Are you using any typescript-auto-importer?