标签: three.jsnode
经过 script 标签导入 three.js 是很好的入门并快速运行的方式,对于长期更新的项目有些不足,好比:webpack
使用像 NPM 这样的依赖管理能避免这些版本问题的不足。git
three.js 已做为 npm 模块发布,详见:npm。只须要运行 npm install three
, three.js 便会包含在你项目之中。github
假定你使用Webpack 或者 Browserify 的打包工具,会容许你在代码中使用 require('modules')
引用打包的全部依赖项。web
你如今应该能在源码中导入模块而且能按常进行。npm
var THREE = require('three'); var scene = new THREE.Scene();
你也能运用 ES6导入语法工具
import * as THREE from 'three'; const scene = new THREE.Scene();
或者你想要导入 three.js 库中的部分,好比导入 Scene:ui
import {Scene} from 'three'; const scene = new Scene();
目前不能经过在 "examples/js"目录下导入全部文件。这是因为有些文件依赖全局命名空间 THREE 而致使污染。详询 Transform examples/js
to support modules #9562.code