Require.js (Magento) problem with Babylon UMD (Webpack) bundling

Hi
I had a problem running Babylon in Magento which uses require.js to import javascript files. The issue was in the UMD definition which I solved (skipped) by replacing the following in the UMD definition
define(“babylonjs”, [], factory) with define( [], factory)
I guess what happened is that AFTER the above replacement require.js used root[“BABYLON”] = factory();.
My issue now is that I can’t import Babylon GUI babylonjs-gui. The reason definitely is that GUI uses Babylon as a dependancy. So if I replace define(“babylonjs-gui”, [“babylonjs”], factory) with define( [“babylonjs”], factory) I get the error
Cannot read property ‘AdvancedDynamicTexture’ of undefined

Anybody can help on this? Can I webpack Babylon.js with Babylon-GUI in one file to avoid the problem?

Adding @RaananW for the require part, but our lib should work with require. This for instance was ok for me:

//The requirejs config
        requirejs.config({
            baseUrl: '.',
            paths: {
                babylonjs: 'https://preview.babylonjs.com/babylon.max',
                
                'babylonjs-gui': 'https://preview.babylonjs.com/gui/babylon.gui',
                'babylonjs-loaders': 'https://preview.babylonjs.com/loaders/babylonjs.loaders',
                'babylonjs-serializers': 'https://preview.babylonjs.com/serializers/babylonjs.serializers',

                'babylonjs-inspector': 'https://preview.babylonjs.com/inspector/babylon.inspector.bundle',
                pep: 'https://code.jquery.com/pep/0.4.3/pep'
            },
            shim : {
                babylonjs: {deps: ['pep']}
            }
        });

        //The main entrypoint to my app
        require([
            'babylonjs',
            'babylonjs-inspector'
        ], function(
            BJS,
            BJSINSPECTOR
        ){...

Hi Jacob, this the config solved the issue? Our package defines the package name (“babylonjs”), and it should be set if you want to load other packages that depend on it.

Would be great to know what the error was the made you make the import anonymous

The problems were

  1. Had to use Babylon ver 4.1+ (was using ver 4.0 with Cannon incorporated)
  2. Most importantly had to use the paths: {} directive, whilst I was using the map:{} directive

However cannot load the physics engine Oimo.js. I am now trying to figure out why.