es6 Import of three.js

后端 未结 2 1968
再見小時候
再見小時候 2021-01-04 13:36

My workflow for es6 uses babel and babel-plugin-transform-es2015-modules-system.js to only transform module import/export for use with system.js. I simply use a \"g

2条回答
  •  时光说笑
    2021-01-04 14:19

    I just had the same problem, but realized that THREE does not export THREE but instead all the different modules. Check the section in the three.js file with the exports:

    exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
    exports.WebGLRenderTarget = WebGLRenderTarget;
    exports.WebGLRenderer = WebGLRenderer;
    exports.ShaderLib = ShaderLib;
    exports.UniformsLib = UniformsLib;
    exports.UniformsUtils = UniformsUtils;
    exports.ShaderChunk = ShaderChunk;
    exports.FogExp2 = FogExp2;
    exports.Fog = Fog;
    exports.Scene = Scene;
    exports.LensFlare = LensFlare;
    exports.Sprite = Sprite;
    exports.LOD = LOD;
    exports.SkinnedMesh = SkinnedMesh;
    exports.Skeleton = Skeleton;
    exports.Bone = Bone;
    exports.Mesh = Mesh;
    exports.LineSegments = LineSegments;
    exports.Line = Line;
    exports.Points = Points;
    exports.Group = Group;
    

    ... etc

    So you can import just the modules you actually need, or as said above: Import all of them via

     import * as THREE from 'three.js'
    

    Cheers

提交回复
热议问题