Load NPM package in Meteor 1.0?

2019-04-24 11:18发布

With the official launch of Meteor, is there a solid way to use NPM packages? I'm trying to use embed.ly but I don't see any straightforward way to do so.

Also, as a meteor novice, how do I include packages in my files? I don't see any 'require' or 'exports' functions.

Thanks!

3条回答
混吃等死
2楼-- · 2019-04-24 11:52

You can install meteorhacks:npm

meteor add meteorhacks:npm
meteor

Meteor will then stop. You can then edit the new package.json file

{
    "request" : "2.33.0"
}

Then when you start Meteor it will install the npm modules for you.

Usage would as follows (use Meteor.npmRequire instead of require)

request = Meteor.npmRequire("request");
查看更多
叼着烟拽天下
3楼-- · 2019-04-24 11:52

In the new "localmarket" example, they include a npm package in the package directory like this:

Request = Meteor.wrapAsync(Npm.require('request'));

and in the package.js file:

Package.describe({
  summary: "Wraps the request module from Npm in a fiber.",
  version: '0.0.0'
});

Npm.depends({request: "2.33.0"});

Package.on_use(function (api) {
  api.add_files('request-server.js', 'server');
  api.export('Request');
});
查看更多
该账号已被封号
4楼-- · 2019-04-24 12:07

You can install this package https://github.com/meteorhacks/npm first. Then use it to require other NPM packages.

查看更多
登录 后发表回答