我使用meteor-typescript-compiler
(https://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
答案 0 :(得分:1)
因此所有Meteor方法都不会被触发并添加到Meteor中。
您需要将main.js文件作为依赖项加载。有人需要调用针对server/main
(System.register("server/main", [], function(exports_1) {
)
阅读文档:https://github.com/systemjs/systemjs#browser我似乎需要
System.import('server/main.js');