es6导入three.js [英] es6 Import of three.js
问题描述
我的es6工作流程使用babel和babel-plugin-transform-es2015-modules-system.js来仅转换模块导入/导出以与system.js一起使用。我只是为所有es6功能使用绿色浏览器,除了模块的导入/导出..这是一个标准,因此不是es6。
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 "green" browser for all es6 features except import/export of modules .. which are a whatwg standard thus not "es6".
这适用于遗产(非es6)库很好,我可以导入我需要的所有npm包。不知何故babel,只有babel模块转换,而system.js神奇地工作。
This works with legacy (non-es6) libraries well, I can "import" all the npm packages I need. Somehow babel, with only the babel modules transform, and system.js magically work.
除了three.js。我尝试了所有三个版本:three.js,three.min.js& three.modules.js。前两个静默失败,导致未定义模块。第三个失败了,想要跟踪..我想是一个类似system.js的转换?
Except for three.js. I tried it with all three releases: three.js, three.min.js & three.modules.js. The first two fail silently, resulting in a "undefined" module. The third fails, wanting traceur .. I guess for a system.js-like transform?
那么我需要做什么才能在我的es6世界中使用three.js ?
So what do I need to do to use three.js in my es6 world?
我想我可以使用< script>
标签和3个全局广告。或者可能使用汇总/网络包来消除模块?
I guess I could just use a <script>
tag and a global for three. Or possibly use rollup/webpack to eliminate the modules?
但我敢打赌,这是一个合理的解决方案。毕竟,three.js在内部使用es6模块。
But I bet there's a reasonable solution. After all, three.js uses es6 modules internally.
推荐答案
发布中有一个错误(只有一天!) 。我修好了但仍有问题。但我确实发现这确实有效:
There was a bug in the release (only one day old!). I fixed it but still had problems. I did however find that this does work:
import * as THREE from 'etc/three.js'
..但更明显的版本,
.. but the more obvious versions,
import THREE from 'etc/three.js'
or
import 'etc/three.js'
似乎不起作用。
如果你比这更好地了解这一点,请相信,这是非常随机的。
Let me know if you grok this better than this, which is pretty random.
这篇关于es6导入three.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!