1.首先先安装three
npm install three --save
2.有的组件 如OrbitControls则不能直接使用,需要安装imports-loader and exports-loader(用于向一个模块的作用域内注入变量、从模块中导出变量)
npm Install imports-loader and exports-loader --save-dev
3.webpack.base.conf.js配置
在其module中的rules[]中添加:
{
test: require.resolve("three/examples/js/controls/OrbitControls"),
use: "imports-loader?THREE=three"
},
{
test: require.resolve("three/examples/js/controls/OrbitControls"),
use: "exports-loader?THREE.OrbitControls"
}
4.引用
import OrbitControls from 'three/examples/js/controls/OrbitControls.js'
网友评论