Tree Shaking Three.js

@cream I’ve tested this out on a simple app that uses GLTFLoader + OrbitControls, no other libraries. This results in about 340kb less (uncompressed) code. That’s great! :grin:

Using the Chrome coverage tool, I’ve gone from about 50% unused JS to 37%.

EDIT: I compared this with the edited src/Three.js file @drcmda shared above, manually removing everything possible and replacing unused classes with empty classes.

I have been able to remove an extra 32kb (again, pre-minification). That brings my code coverage down to 35.5%.

Here are my results:

Initial size: 1323kb
Using @cream’s technique: 981kb
Manually editing src/Three.js: 949kb

Manually editing the src/ code is a lot of extra work for diminishing returns. I don’t think it’s worth it, personally.

2 Likes