JSPM Builder:如何依赖其他模块?

JSPM Builder: How to depend on other module?

我使用 TypeScript 编译器为我的 JSPM Build 配置了以下配置:

var Builder = require('jspm').Builder;

var builder = new Builder('.');
    builder.reset();

builder.loadConfig('./jspm.conf.js')
    .then(function() {

        builder.config({
            defaultJSExtensions: false,
            transpiler: "typescript",
            typescriptOptions: {
                "module": "system",
                "experimentalDecorators": true,
                "resolveAmbientRefs": true
            },
            packages: {
                "source": {
                    "main": "app/index",
                    "defaultExtension": "ts",
                    "meta": {
                        "*.ts": {
                            "loader": "ts"
                        },
                        "*.css": {
                            "loader": "css"
                        }
                    }
                }
            },
            packageConfigPaths: [
                "npm:@*/*.json",
                "npm:*.json",
                "github:*/*.json"
            ],
            meta: {
                "three": {
                    "format": "global",
                    "exports": "THREE"
                },
                "three-firstpersoncontrols": {
                    "deps": "three"
                }
            },
            map: {
                "three": "github:mrdoob/three.js@r79/build/three.js",
                "three-firstpersoncontrols": "github:mrdoob/three.js@r79/examples/js/controls/FirstPersonControls.js"
            }
        });

        var promises = new Array();

        promises.push(builder.buildStatic('source', './build/js/app.min.js', {
            sourceMaps: false,
            minify: true,
            mangle: false
        }));

        return Promise.all(promises);
    })
    .then(function() {
        cb();
    })
    .catch(function(err) {
        console.log('Build Failed. Error Message: ', err);
    });

我正在尝试使用 THREE.js 库以及包含功能的单独文件,例如FirstPersonControls。路径在 map 部分中定义,这些都可以正常工作。

捆绑后,我收到 THREE.FirstPersonControls is not a contructor 的消息。到目前为止,我的猜测是单独的模块 three-firstpersoncontrols 不依赖于全局 THREE 变量,因此无法调用构造函数 THREE.FirstPersonControls.

所以我的问题变成了:

如何让这些单独的模块依赖于构建中的全局 THREE 模块?

过了一会儿我发现问题出在这部分:

typescriptOptions: {
    "module": "system", // <-- THIS LINE
    "experimentalDecorators": true,
    "resolveAmbientRefs": true
}

我必须将我的模块格式从 system 更改为 amd 才能工作,所以现在配置已变为:

typescriptOptions: {
    "module": "amd",
    "experimentalDecorators": true,
    "resolveAmbientRefs": true
}

希望有此问题的其他人可以使用此答案。