Three-onlymath.min.js

I have a file from a project I got from somebody else called three-onlymath.min.js. It’s only 72kb which is perfect.
How do I obtain the latest version of this file?
On github I can only find three.module.min.js which is almost 10 times as big.

What is

Is it a standalone copy of this?

I’m guessing it’s either this file or it’s a build of this folder

1 Like

Here is the file in question:

I think it’s a build of the folder in question - but from your answers I take it that this is something that has been done as a custom one-off job before I got the file. How hard would it be to re-build something similar?

Disclaimer: Personally I would use a bundler like Vite, as described in the three.js installation guide. It will handle “tree-shaking” parts of three.js you’re not using automatically. No need to build these mini-bundles manually. But if you do want to create a math-only build of three.js manually …


  1. Create a new folder and install three.js locally, or copy the full module from somewhere else.
  2. Create a file that exports only the parts of three.js you need, like:
// three-math.js
export {
  Vector2, Vector3, Vector4, Matrix3, Matrix4, Euler, Quaternion, MathUtils
} from 'three';
  1. Compile the bundle.
npx microbundle build --target web --no-compress -i three-math.js -o dist/ --format modern --external none
  1. Take the compiled bundle from dist/three-math.modern.mjs.
4 Likes

Beautifully elegant :ok_hand: