Bundle size, ES6 import

Hello, in : ES6 - Babylon.js Documentation I see 2 ways of importing e.g the Scene :

a) import { Scene } from ‘@babylonjs/core’;
and
b) import { Scene } from “@babylonjs/core/scene”;

Are these any different or equivalent? Do they make any difference in the bundle size?

Thank you for your time!

Hi,

good question :slight_smile:

Since we are not side-effects free, there is a difference between the first and the second.

You can read about it further here - Tree Shaking | webpack , but the general gist is this -

The first will load all files with side-effects defined in core (and will execute the free code in all of them) . If there are any, they will all be included. The second will only load “everything” from the scene file, which is technically only the scene itself.

It also depends what your output is, what packer you are using, what is your target etc’… Technically, not considering package size, they are the same - you will have a reference to the Scene class :slight_smile:

1 Like

many thanks for your swift reply RaananW!
Could you also please clarify what happens with package size? which one - if any - is better?
( I am using webpack, target would be web. I am really just interested in minimizing the babylon bundle size as much as possible , currently stands at 611kb unzipped )

The best would be to load from the most specific path, while taking care of side-effects yourself (as described in the documentation page you pasted before). That will keep the bundle size to the minimum needed for the features you are using

1 Like

ok will give it a try, many thanks for your support RaananW!

1 Like