2016-08-19 51 views
0

我有我的JSPM Build以下配置使用打字稿編譯:JSPM Builder:如何依賴其他模塊?

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/[email protected]/build/three.js", 
       "three-firstpersoncontrols": "github:mrdoob/[email protected]/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.jsFirstPersonControls。路徑在map部分中定義,並且這些都工作得很好。

捆綁後,我得到的消息是THREE.FirstPersonControls is not a contructor。目前我的猜測是,單獨模塊three-firstpersoncontrols不依賴於全局THREE變量,因此無法調用構造函數THREE.FirstPersonControls

所以我的問題是:

如何讓這些單獨的模塊依賴我的全球THREE模塊上構建?

回答

0

過了一會兒,我發現了問題是這個部分:

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

我有我的模塊格式改變從systemamd工作,所以現在的配置已經成爲:

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

希望有這個問題的任何人都可以使用這個答案。