# Treeshaking core/flowgraph?

**URL:** <https://forum.babylonjs.com/t/treeshaking-core-flowgraph/57104>\
**Category:** Questions\
**Tags:** gltf\
**Created:** [March 13, 2025, 1:51pm UTC](https://forum.babylonjs.com/t/treeshaking-core-flowgraph/57104 "2025-03-13T13:51:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yedpodtrzitko](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yedpodtrzitko](https://forum.babylonjs.com/u/yedpodtrzitko)\
**Post date:** [March 13, 2025, 1:51pm UTC](https://forum.babylonjs.com/t/treeshaking-core-flowgraph/57104/1 "2025-03-13T13:51:23Z")

</div>

Hi,  
I have noticed that the size of `core/flowgraph` module is gradually growing over time. For example between the version `7.51.0` and `7.52.0`, it got more than twice as big (123kB → 309kB, according to BundleAnalyzer). While this sure means there are more features now, I’m slightly worried of this trend which is increasing the final size of bundle.

Since I dont observe any difference in functionality in my project between the aforementioned versions, I might be convinced that I dont need most of the `core/flowgraph` anyway. So maybe Is there any way how to treeshake the module while still keeping support for gltf models in my project? 🤔

I have tried to trim it via `resolve.alias` in webpack config, but it produces an error:

```auto
resolve: {
    alias: {
      "@babylonjs/core/FlowGraph": false,
    }
}

```

the bundle size can be observed with the project template from Raanan:  
`$ git clone https://github.com/RaananW/babylonjs-webpack-es6/`

```diff
diff --git a/src/createScene.ts b/src/createScene.ts
index ebfe4c4..a4c8e39 100644
--- a/src/createScene.ts
+++ b/src/createScene.ts
@@ -3,6 +3,7 @@ import type { Scene } from "@babylonjs/core/scene";
 // Change this import to check other scenes
 import { DefaultSceneWithTexture } from "./scenes/defaultWithTexture";
 import { AbstractEngine } from "@babylonjs/core/Engines/abstractEngine";
+import { LoadModelAndEnvScene } from "./scenes/loadModelAndEnv";

 export interface CreateSceneClass {
     createScene: (engine: AbstractEngine, canvas: HTMLCanvasElement) => Promise<Scene>;
@@ -14,5 +15,5 @@ export interface CreateSceneModule {
 }

 export const getSceneModule = (): CreateSceneClass => {
- return new DefaultSceneWithTexture();
+ return new LoadModelAndEnvScene();
 }
diff --git a/webpack.common.js b/webpack.common.js
index 00b42e7..1c472e1 100644
--- a/webpack.common.js
+++ b/webpack.common.js
@@ -2,7 +2,7 @@ const path = require("path");
 const fs = require("fs");
 const HtmlWebpackPlugin = require("html-webpack-plugin");
 const { CleanWebpackPlugin } = require("clean-webpack-plugin");
-// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
+const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

 // App directory
 const appDirectory = fs.realpathSync(process.cwd());
@@ -55,7 +55,7 @@ module.exports = {
         ],
     },
     plugins: [
- // new BundleAnalyzerPlugin(),
+ new BundleAnalyzerPlugin(),
         new CleanWebpackPlugin(),
         new HtmlWebpackPlugin({
             inject: true,

```

`$ npm install @babylonjs/core@7.51.0 @babylonjs/loaders@7.51.0`  
`$ npm run start`  
// check the flowgraph size

`$ npm install @babylonjs/core@7.52.0 @babylonjs/loaders@7.52.0`  
`$ npm run start`  
// check the flowgraph size

Thanks.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [March 13, 2025, 3:39pm UTC](https://forum.babylonjs.com/t/treeshaking-core-flowgraph/57104/2 "2025-03-13T15:39:36Z")

</div>

Core/FlowGraph should have no reference from within core, so it should be tree-shaken out, if you import from the right modules.  
Unless I missed something, and in this case I will fix it asap.  
I assume you are importing directly from `@babylonjs/core`?

\*\*EDIT - could be a reference from loaders. how are you loading the loaders package?

---

<div class="post-metadata">

**Author:** ![yedpodtrzitko](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yedpodtrzitko](https://forum.babylonjs.com/u/yedpodtrzitko)\
**Post date:** [March 13, 2025, 4:17pm UTC](https://forum.babylonjs.com/t/treeshaking-core-flowgraph/57104/3 "2025-03-13T16:17:44Z")

</div>

Thanks for your response.

> I assume you are importing directly from `@babylonjs/core`?  
> how are you loading the loaders package?

I’m careful to not import anything directly from `core`, so this shoudn’t be the case. My import same as in your template, ie.:

`import "@babylonjs/loaders/glTF";`

> <https://github.com/RaananW/babylonjs-webpack-es6/blob/ec83a9678d205e5e80d3e17466b3f2380c015e6d/src/scenes/loadModelAndEnv.ts#L12>

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [March 13, 2025, 4:43pm UTC](https://forum.babylonjs.com/t/treeshaking-core-flowgraph/57104/4 "2025-03-13T16:43:47Z")

</div>

This needs to be updated with the dynamic extensions support, i guess. You also don’t need glTF 1.0, which is included here as well. let me see if I can update the template really quick and test it.

You should not have interactivity/flowgraph loaded, unless you need it.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [March 13, 2025, 6:32pm UTC](https://forum.babylonjs.com/t/treeshaking-core-flowgraph/57104/5 "2025-03-13T18:32:20Z")

</div>

ok, I just made an update to the template. try changing the import to:

`import "@babylonjs/loaders/glTF/2.0/glTFLoader";`

This will avoid loading any glTF extensions. If yuo do need a glTF extension you can import them individually, or use the dynamic `registerBuiltInGLTFExtensions` function that will async-load them when they are needed (and generate chunks for them)

---

<div class="post-metadata">

**Author:** ![yedpodtrzitko](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yedpodtrzitko](https://forum.babylonjs.com/u/yedpodtrzitko)\
**Post date:** [March 14, 2025, 12:13am UTC](https://forum.babylonjs.com/t/treeshaking-core-flowgraph/57104/6 "2025-03-14T00:13:00Z")

</div>

> `import "@babylonjs/loaders/glTF/2.0/glTFLoader";`

Yup, that helps. Thanks again.
