我有一个 Three.js 场景,它只使用了库的一部分。
import {
Scene,
PerspectiveCamera,
WebGLRenderer,
BoxGeometry,
MeshBasicMaterial,
Mesh} from 'three';
但我最终还是得到了整个库中的大部分(如果不是全部的话)(缩小了约 500Kb)。有没有人有这方面的运气?我有一个 example GitHub这显示了我正在使用的代码。
最佳答案
我目前在一个项目中使用 WebPack2 并切换到使用内置的 tree-shaking。让我们来看看这些步骤:
npm install three
import {Something} from 'three';
时发生的事情在你的代码中。为此,我使用 alias-setting使用较新的 three.js 版本中包含的备用模块构建: {
resolve: {
extensions: ['.js'],
modules: [SRC_PATH, 'node_modules'],
alias: {
'three': path.join(__dirname, 'node_modules/three/build/three.module.js')
}
}
}
babel-preset-es2015-native-modules
代替)。 this blog-post 中有更多相关信息。 . 关于three.js - 如何使用 WebPack 或 Rollup 摇树 Three.js?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41538767/