Using webpack, threejs examples, and typescript?

后端 未结 4 1985
逝去的感伤
逝去的感伤 2021-02-02 17:20

I\'m having a lot of trouble getting stuff in threejs\'s examples (like EffectComposer or Detector) to work with webpack and typescript.

First off the relevant *.d

4条回答
  •  日久生厌
    2021-02-02 18:17

    Here's what worked for me.

    $ npm install --save-dev exports-loader imports-loader
    

    Then, to use something from three/examples/js, I do this:

    const THREE = require('three');
    // imports provides THREE to the OrbitControls example
    // exports gets THREE.OrbitControls
    THREE.OrbitControls = require('imports?THREE=three!exports?THREE.OrbitControls!../../node_modules\/three\/examples\/js\/controls\/OrbitControls');
    
    // use THREE.OrbitControls ...
    

    I think the right thing to do is use the imports and exports loaders by config rather than embedding them in the require. I'll update this answer when I have an example.

提交回复
热议问题