I’m trying to package my application using Webpack but face two errors I find somewhat hard to debug.
When not applying any form of tree shaking the distributable file becomes over 6,5mb large at the hands of the Babylon files. When I attempt to download the core package and include only the functionality I desire the loading of meshes fails. When reverting back to including the entire Babylon file it works as should be (parameters simplified for readability):
SceneLoader.ImportMesh('', `./path/`, "scene.gltf", this.scene, function(newMeshes){
const root = newMeshes[0]; //Get root element
root.getChildMeshes().forEach(function(child){
child.material = w;
}.bind(this))
root.scaling = new Vector3(0.05, 0.05, 0.05);
root.setAbsolutePosition(new Vector3(
v * Math.cos(x),
-1,
y);
}.bind(this));
When using
import * as BABYLON from 'babylonjs';
import 'babylonjs-loaders'
BABYLON.SceneLoader.ImportMesh()
this works fine. However, when using
import { SceneLoader } from "@babylonjs/core/"
import 'babylonjs-loaders'
BABYLON.SceneLoader.ImportMesh()
it fails. The set up of instantiating the engine and scene already work - it is merely the ImportMesh that doesn’t want to work. It gives me the error:
Unable to import meshes from ./meshes/Table/scene.gltf: importMesh of unknown
My intuition would be that perhaps it is missing other files I need to import, but even when importing everything from the Meshes directory, which go unused may I add, this still fails.
Since I’m here whining anyway; I’m also facing the problem of tree shaking doing absolutely nothing for the overall size of the produced distributable (by Webpack); I was told tree shaking should prevent the entire Babylonjs library from being included, but that doesn’t appear to be happening.