百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

three-minifier

> 编程语言
开源

压缩 THREE.js

196 stars0 点赞4 次浏览
访问官网GitHub

工具介绍

压缩 THREE.js

three-minifier

Minify THREE.js

Introduction

This plugin helps projects who use THREE.js shrink their size by:

  • Resolve three / three/build/three.module.js to three/src/Three.js.
    • This makes it possible for bundlers to perform better tree-shaking.
  • Mark three as side-effect free.
  • Replace WebGL constants with literals.
  • Minify GLSL files.

This plugin also resolves three-nodes and three-addons modules.

Requirements

  • node >= v12.0
  • three.js >= r120
  • Webpack plugin requires Webpack 5

Usage

Rollup

bash
npm install --save-dev @yushijinhun/three-minifier-rollup

rollup.config.js:

javascript
import { threeMinifier } from "@yushijinhun/three-minifier-rollup";
...
export default {
	...
	plugins: [
		threeMinifier(), //  {
		if (!isServer && !dev) {
			config.cache = false;
			const threeMinifier = new ThreeMinifierPlugin();
			config.plugins.unshift(threeMinifier);
			config.resolve.plugins.unshift(threeMinifier.resolver);
		}
		return config;
	},
};

Vite & SvelteKit

Most Rollup plugins are compatible with Vite, including three-minifier. SvelteKit uses Vite as its build tool, so the setup is the same as for Vite.

bash
npm install --save-dev @yushijinhun/three-minifier-rollup

vite.config.(js|ts):

javascript
import { defineConfig } from "vite";
import { threeMinifier } from "@yushijinhun/three-minifier-rollup";
// import { sveltekit } from '@sveltejs/kit/experimental/vite';

export default defineConfig({
	plugins: [
		{ ...threeMinifier(), enforce: "pre" }, //  354K
 * Webpack: 582K => 354K

### Do I need to modify any existing code?
No. These are the acceptable approaches to importing THREE.js:
```javascript
import { ... } from "three";
import { ... } from "three/build/three.module.js";
import { ... } from "three/src/Three";
import { ... } from "three/src/math/vector3";
// or something like these

Does this work with examples jsm modules?

Yes. This plugin solves mrdoob/three.js#17482.

You do not need to do any extra work to use examples jsm modules.

javascript
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
// import { OrbitControls } from "three-addons/controls/OrbitControls"; // equivalent to the previous one

import { NodeMaterial } from "three/examples/jsm/nodes/materials/Materials";
// import { NodeMaterial } from "three-nodes/materials/Materials"; // equivalent to the previous one

Will one day I no longer need this plugin?

In order to make THREE.js tree-shakable, efforts have been made by many people on the upstream project. However, THREE.js hasn't come up with a feasible solution so far. See related issues to learn more.

Related issues & repositories

  • Importing examples jsm modules causes bundlers to bundle three.js source code twice mrdoob/three.js#17482
  • ReactAreaLights do not seem to work in a module bundler mrdoob/three.js#17220
  • Add sideEffects: false flag to package.json to allow tree shaking mrdoob/three.js#16059
  • Allow tree-shaking by adding "sideEffects": false flag mrdoob/three.js#16317
  • Enable tree-shaking both for the main and examples files mrdoob/three.js#16301
  • Support esm on node with conditional exports mrdoob/three.js#18498
  • Examples: add three/addons/* alias mrdoob/three.js#23406
  • Avoid bare imports other than 'three' mrdoob/three.js#23625
  • Add three/addons (for npm users only) mrdoob/three.js#23368
  • vxna/optimize-three-webpack-plugin
  • mattdesl/threejs-tree-shake

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptjavascriptrollupthreejswebpack

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言