在Meteor包中使用npm

Lt.*_*Lt. 3 npm meteor

试图找出将npm包加载到Meteor中的方法.具体来说我试过了future-npm

我试过这样做:

Package.describe({
  summary: "Blah blah",
  version: '0.0.1'
});

Npm.depends({future: "2.3.1"});

Package.onUse(function (api) {
  api.addFiles('lubert.js', 'server');
  api.export('Lubert');
});
Run Code Online (Sandbox Code Playgroud)

不幸的是我得到了以下控制台错误

 Uncaught ReferenceError: Npm is not defined
Run Code Online (Sandbox Code Playgroud)

我已阅读文档,没有任何关于加载任何依赖项

我究竟做错了什么?

更新2:我的package.js看起来像

Package.describe({
  name: 'trepafi:package',
  summary: '',
  version: '0.0.3',
  git: 'https://github.com/trepafi/meteor-package.git'
});

Npm.depends({
  "future": "2.3.1"
});

Package.onUse(function(api) {
  api.versionsFrom('1.0');
  api.use(['tracker', 'underscore'], ['client']);
  api.addFiles(['package.js'], ['client']);
  api.export('Package', ['client']);
});
Run Code Online (Sandbox Code Playgroud)

更新1:我的package.json看起来像

{
  "name": "trepafi-package",
  "version": "0.0.3",
  "description": "Package for Meteor",
  "repository": {
    "type": "git",
    "url": "https://github.com/trepafi/meteor-package.git"
  },
  "author": "Lubert Palacios",
  "license": "MIT",
  "homepage": "https://github.com/trepafi/meteor-package",
  "dependencies": {
    "future": "^2.3.1"
  }
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过meteorhacks:npm没有成功.如果我可以使用"原生"方式,那就太好了

Set*_*aki 5

您应该将文件Npm.require末尾的所有内容分组package.js.

为了future-npm.你不需要Npm.dependspackage.js,傻.它已经包含在流星中..只是在Npm.require某个地方,你很高兴去.要做到这一点:

  1. 不要暧昧这个package.js名字.使用trepafi:package.js来代替.

  2. 你不需要package.json...... Npm.depends让你满意.

  3. 删除这个:api.addFiles(['package.js'], ['client']);因为它看起来像一个循环的依赖.. 哟dawg我牧你在你的包裹.js的谎言package.js ..不酷,Xzibit.

  4. 由于Npm.require仅适用于服务器端,因此您需要包含trepafi:package.js在服务器端.例如:

    api.addFiles(['trepafi:package.js'], ['server']);

所以你的结构至少应该是:

trepafi:package/
  - package.js
  - trepafi:package.js
  - <other files..>
Run Code Online (Sandbox Code Playgroud)

你不需要package.json Future..它已经包含在Meteor中.

package.js应该看起来像:

Package.describe({
  name: 'trepafi:package',
  summary: '',
  version: '0.0.3',
  git: 'https://github.com/trepafi/meteor-package.git'
});

Package.onUse(function(api) {
  api.versionsFrom('METEOR@1.0');
  api.use(['tracker', 'underscore','meteor'], ['client']);
  api.addFiles(['trepafi:package.js'], ['server']);
  api.export('Package', ['client']);
});

//if you really need Npm.depends:

Npm.depends({
   'prerender-node': '1.0.6',
   'send' : '0.10.1'
});

// we don't need no package.json
Run Code Online (Sandbox Code Playgroud)

trepafi:package.js应该看起来像:

var Future = Npm.require('future');
var future = new Future();

// use your future to make Doc Brown proud.

var useFuture = function(asyncFunc) { //expects function with callback somewhere
    asyncFunc(function(err, result) {
        if(err) future.throw("OMG something went wrong!");
        else return future.return(result);
    });
    return future.wait();
};

Meteor.startup(function() {
   //something      
});
Run Code Online (Sandbox Code Playgroud)

读:

值得注意的变化在package.jsARE versionsFromapi.use现在已经meteor加入其中.

祝好运!