Treeshaking ShaderWGSL

I’m on a bit of treeshaking journey trying to get my bundle size down currently BabylonJS is sitting just over 2000kB (not compressed).

While investigating I noticed that materials (pbrBaseMaterial and StandardMaterial in my specific case) load in Shaders and ShadersWGSL, as I’m not using WebGPU I imagine ShadersWGSL will be loaded and never touched? Is there anything I can do to shake this out?

dist/static/babylon.js 2,018.82 kB │ gzip: 462.55 kB
dist/static/loaders.js 80.09 kB │ gzip: 19.78 kB

I appreciate Babylon is a super complex bit of code and will be quite large regardless but I’m just seeing what I can shave off :sweat_smile:

Thanks for all your hard work :heart:

cc @ryantrem

In various places we do dynamic imports of either glsl or wgsl shaders, depending on what engine is being used. If you aren’t configuring your bundler to do code splitting / chunking, then all these dynamically imported dependencies will end up in your bundle. I think the only thing you can do in that case is add additional bundler configuration to explicitly exclude certain sources.