在使用带有SystemJs的typescript时,无法在运行时添加Meteor方法

时间:2015-11-30 04:34:13

标签: meteor typescript

我使用meteor-typescript-compilerhttps://github.com/meteor-typescript/meteor-typescript-compiler)作为我的新项目。在设置项目并获得@basarat的大力帮助后,我能够让项目正常启动。但是,看起来生成的js文件在执行服务器时没有被触发,因此所有Meteor方法都不会被触发并添加到Meteor中。

/// <reference path="../typings/definitions/meteor.d.ts" />


export class App {
  constructor() {
  }
}

Meteor.startup(function() {
   console.log ('added to stack');
});

Meteor.methods({
  'test': function() {
     console.log('from new 2');
  }
});

启动流星服务器时,生成的js文件为

(function(){

/////////////////////////////////////////////////////////////////////////
//                                                                     //
// server/main.js                                                      //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
                                                                       //
/// <reference path="../typings/definitions/meteor.d.ts" />            // 1
System.register("server/main", [], function(exports_1) {               //
    var App;                                                           //
    return {                                                           //
        setters:[],                                                    //
        execute: function() {                                          //
            App = (function () {                                       //
                function App() {                                       //
                }                                                      //
                return App;                                            //
            })();                                                      //
            exports_1("App", App);                                     //
            Meteor.startup(function () {                               //
                console.log('added to stack');                         //
            });                                                        //
            Meteor.methods({                                           //
                'test': function () {                                  //
                    console.log('from new 2');                         //
                }                                                      //
            });                                                        //
        }                                                              //
    }                                                                  //
});                                                                    //
//# sourceMappingURL=main.js.map                                       //
/////////////////////////////////////////////////////////////////////////

}).call(this);

//# sourceMappingURL=main.js.map

这是我的tsconfig.json(我还根据meteor-typescript-compiler的指导将.tsconfig添加到根文件夹中)

{
    "compilerOptions": {
        "module": "commonjs",
        "sourceMap": true,
        "isolatedModules": false,
        "noImplicitAny": true
    },
    "exclude": [
        "typings"
    ]
}

服务器运行时未显示行added to stack(我将包systemjs:systemjs添加到流星中)。出于测试目的,我将项目上传到https://github.com/bubuzzz/new1.git

1 个答案:

答案 0 :(得分:1)

  

因此所有Meteor方法都不会被触发并添加到Meteor中。

您需要将main.js文件作为依赖项加载。有人需要调用针对server/mainSystem.register("server/main", [], function(exports_1) {

注册的功能

阅读文档:https://github.com/systemjs/systemjs#browser我似乎需要

System.import('server/main.js');