Javascript files from the examples folder (such as OrbitControls) are not CommonJS or ES Modules, but they can still be used in Webpack bundles:
In package.json
:
"dependencies": {
"three": "0.84.0",
"webpack": "2.4.1"
}
In webpack.config.js
:
resolve: {
alias: {
'three/OrbitControls': path.join(__dirname, 'node_modules/three/examples/js/controls/OrbitControls.js'),
'three/OBJLoader': path.join(__dirname, 'node_modules/three/examples/js/loaders/OBJLoader.js')
// ...
}
},
//...
plugins:[
new webpack.ProvidePlugin({
'THREE': 'three'
}),
//...
]
In application.js
(CommonJS version):
require('three');
require('three/OrbitControls');
/* global THREE */
console.log(THREE.OrbitControls);
In application.js
(ES Modules version):
import 'three';
import 'three/OrbitControls';
/* global THREE */
console.log(THREE.OrbitControls);
Just a side note in case anyone else was having trouble, I needed to use
import 'three/examples/js/loaders/OrbitControls';
. The rest was perfect though, thanks!