问题描述
我使用了 meteor-typescript-compiler
(https://github.com/meteor-typescript/meteor-typescript-compiler) 用于我的新项目.设置好项目并得到@basarat
的大力帮助后,让项目正常启动.但是,看起来生成的 js 文件在 server 执行期间没有触发,因此所有 Meteor 方法都没有触发并添加到 Meteor.
I used meteor-typescript-compiler
(https://github.com/meteor-typescript/meteor-typescript-compiler) for my new project. After setting up the project and getting the great help from @basarat
, I was able to let the project startup normally. However, look like the generated js file is not triggered during the time server is executed, thus all the Meteor methods are not triggered and added to 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文件为
When starting up the meteor server, the generated js file is
(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 添加到根文件夹)
And this is my tsconfig.json
(I also added the .tsconfig to the root folder based on the meteor-typescript-compiler
's guidance)
{
"compilerOptions": {
"module": "commonjs",
"sourceMap": true,
"isolatedModules": false,
"noImplicitAny": true
},
"exclude": [
"typings"
]
}
服务器运行时不显示加入堆栈
行(我将包systemjs:systemjs
添加到meteor中).出于测试目的,我将项目上传到 https://github.com/bubuzzz/new1.git一个>
The line added to stack
is not shown when server is running (I added package systemjs:systemjs
into meteor). For the testing purpose, I uploaded the project into https://github.com/bubuzzz/new1.git
推荐答案
您需要加载 main.js 文件作为依赖项.即有人需要调用针对 server/main
注册的函数(在 System.register("server/main", [], function(exports_1) {
)
You need to load the main.js file as a dependency. i.e someone needs to call the function that is registered against server/main
(in System.register("server/main", [], function(exports_1) {
)
阅读文档:https://github.com/systemjs/systemjs#browser看来你需要
System.import('server/main.js');
这篇关于在 SystemJs 中使用 typescript 时,无法在运行时添加 Meteor 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!