Build instructions

Mr.doob edited this page Aug 11, 2018 · 6 revisions

This page describes how to compile three.js into a compressed Javascript file.

Quickstart

  • Install Node.js.

  • Clone (or download and unzip) the project to your file system:

git clone https://github.com/mrdoob/three.js.git
  • Go into the three.js directory.
cd ./three.js
  • Install build dependencies
npm install
  • Run the build script.
npm run build-uglify

The compiled file is at three.js/build/three.min.js, with three.js being the uncompressed concatenated file.


Other builds:

  • npm run build: Concatenation only, no compression.
  • npm run build-closure: Compile using the Google Closure Compiler. This is the primary method, but requires Java 7 or higher.
  • npm run dev: Watches the files in 'src' folder and automatically concatenate (npm run build) when source files are changed

Why compression?

The source code of Three.js is deliberately easy to read. This means that it's split into several files and classes. While that's great for developing and hacking on Three.js, it's not that great when deploying code to the production server.

In production, you want to

  • use the least amount of files possible (to minimize the number of connections to your server)
  • transmit as few bytes as possible (to save on bandwidth and on wait-time on both sides)

So how do we put all files into just one and make it smaller than the sum of the parts? Well, the answer is the awesome combination of our build script plus Javascript compressors!

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.