In my webpack config:
resolve: {
alias: {
'three': path.resolve('node_modules', 'three/build/three.js'),
'OrbitControls': path.resolve('node_modules', 'three/examples/js/controls/OrbitControls.js'),
'OBJLoader': path.resolve('node_modules', 'three/examples/js/loaders/OBJLoader.js')
}
In my module:
import * as THREE from 'three' // if I do import THREE from 'three' it fails with three being undefined
import OrbitControls from 'OrbitControls'
import OBJLoader from 'OBJLoader'
If I use import * THREE from 'three'
all is well and I can get THREE to be defined and complete the cube tutorial without hassle. If I change to import * as THREE from 'three'
three.js is loaded - so that's not the problem?
How do I get the OrbitControls
and the OBJLoader
to load? When I try to get them to load, I get Uncaught ReferenceError: THREE is not defined(…)
within OrbitControls.js
: THREE.OrbitControls = function ( object, domElement ) {
THREE is undefined.
So there's a problem with the packaging of the modules? I installed this from https://www.npmjs.com/package/three
So what gives? Is it a problem how Three.js is packaged on npm or is it a misconfiguration in my webpack.config? Is there a way to tell webpack "let's package the root three.js file, and then package the OrbitControls.js file"?