I’m working on BabylonJS v 4.2 and I do not want to use StandardMaterial at all in my project. To limit bundle size. But I’m starting to have this error.
This import sorts the problem out but I will not use this material at all.
Also, I can import it rebuild and after the error is gone, remove this import, and app works just fine for some time. And then it’s again starting to show up.
How to fix the fact that I will not use it on the Ground with a displacement and primitive meshes created with a MeshBuilder.
Can I remove it during the build? so have like lazy loading if it’s NODE_DEV=‘development’ and then removed it from the final build? Or will I have an error?
You will need to make sure all meshes have a material right after they are created (or pre-render), otherwise the standard material will be initialized. Technically you would need to make sure that defaultMaterial is never accessed.
I moved to version 5.4 and I still get StandardMatarial bundled in and bloating my size, but I moved everything to NodeMatarial so I do not use it at all.
And it works without any imports as long as 1st line after creating a mesh I setup the material to be node material, so this is all good.
But I cant bundle it out in any way cause its used in other classes that I use but I do not use them with StandardMaterial, like:
No. Unfortunately. But this is this. How we can not import it at all? You got now have options to choose from, and I’m choosing NodeMaterial.
There are other Packages that I never use as well like: Bones, Lights, ParticleEmitters, Procedural Textures and more that I do not use at all but they are in the bundle.
But surprisingly to add engine views methods I need to add one more import to make them work
So why not add import next to your scene to make a choice of your default and maybe only material? Like this:
That’s because of the way we build, import, and separate modules. We are trying to decouple as much as possible, but it is sometimes not possible.
I am not sure which one of the modules you are importing is using the standard material. we are doing our best to minimize the amount of unneeded packages you are using, but sometimes it requires a major overhaul of architecture, which might be an issue.
If you can share a reproduction project it would be great. I will be able to help better if I knew what packages you are importing and how we can fix that
I just got the scene. But all the rest mentioned above are also there.
I do not have any light and I got it. I do not have any imported Mesh But I do have Bones.
I was thinking this modular thing will be separating the stuff we do not use.
I like the idea of having an initial boilerplate depending on what you will use I do not mind.
But now I got imports that I was not aware I’m bundling in even.
There is a way to get down to gzip 120kB apparently but I can’t get any lower than 340kB. But I see in my bundle stuff that I definitely now use at all.
Have you read our tree shaking documentation and the caveats?
Yes, it should work as you describe, but since we are backwards compatible, and always backwards compatible, it is hard to change the architecture without breaking things.
We are planning on creating a new package (esm) that will be independent and support full tree-shaking. Until then, these are the limitations of the packages we provide.