# threejs-tree-shake **Repository Path**: mirrors_mattdesl/threejs-tree-shake ## Basic Information - **Project Name**: threejs-tree-shake - **Description**: Tree-shakes and optimizes ThreeJS apps - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-09 - **Last Updated**: 2026-05-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # threejs-tree-shake [![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges) A browserify plugin to tree-shake and optimizes a ThreeJS application. > :rotating_light: Still highly experimental and unstable, but feel free to try it out. Tested with browserify@15 and Three r89. This parses your source AST to find which ThreeJS modules your app actually uses. Then it runs [rollup](https://github.com/rollup/rollup) on the fly to generate a much smaller ThreeJS module. It's not ideal, and may break with future ThreeJS changes or in certain applications. After minification on a simple example app, the bundle size goes from 533 kB to 320 kB. Other apps may have more or less savings depending on how many modules you require. ## Quick Start This works with CommonJS `require` or relying on `THREE` as a global namespace. It also works with `import` statements, although typically you will transpile them with the `babelify` transform. Here is an example with CommonJS: ```js var THREE = require('three'); var renderer = new THREE.WebGLRenderer(); renderer.setPixelRatio(window.devicePixelRatio); renderer.setSize(256, 256); var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera(45, 1, 0.01, 100); camera.position.z = -4; camera.lookAt(new THREE.Vector3()); var geometry = new THREE.SphereGeometry(1, 32, 32); var mesh = new THREE.Mesh(geometry, new THREE.MeshNormalMaterial()); scene.add(mesh); renderer.render(scene, camera); document.body.appendChild(renderer.domElement); ``` Now, you will need to install the tool in your local repo. ```sh # make sure three is installed as a local dependency # this way, you can call require('three') npm install three --save # install the necessary tooling npm install browserify threejs-tree-shake --save-dev # run browserify to generate a final bundle npx browserify myApp.js -p threejs-tree-shake > bundle.js ``` > :bulb: In this case the `npx` command will run our locally-installed tools (i.e. within node_modules folder). The final bundle will be much smaller than usual since many ThreeJS modules will get discarded (e.g. various materials, constants, geometries, helpers, and legacy functions you won't need). ## Loose Search In many cases you will have a ThreeJS app that doesn't `import` or `require` ThreeJS in every file (e.g. if you are using a `