首页 > 解决方案 > 将 THREE.js 与 aurelia-cli 一起使用,导出为全局

问题描述

安装三个.js:npm install three

配置aurelia.json

"dependencies": [
      {
        "name": "three",
        "path": "../node_modules/three/build",
        "main": "three.min"
      }

导入视图:import * as THREE from 'three';

好的,所以这可行,我可以使用three.js,但是,我也想使用一些插件。具体来说GPUParticleSystem。现在这个插件依赖于一个全局THREE对象。在第一次尝试中,我将其添加到aurelia.json

"dependencies": [
          {
            "name": "three",
            "path": "../node_modules/three/build",
            "main": "three.min",
             "exports": "THREE" //this should make the library a global object?
          }

但它似乎不起作用?我无法从 devTools 中看到全局变量。

标签: three.jsaurelia

解决方案


解决此问题的一种可能方法是使用prependin aurelia.json

...
"prepend": [
    "node_modules/three/build/three.min.js",
    "node_modules/three/examples/js/GPUParticleSystem.js"
 ]
...

推荐阅读