简体   繁体   中英

How do you include 3rd party javascript libraries in Meteor.js?

In meteor if I want to use a 3rd party javascript library such as gridster.js ( http://gridster.net/ )

How do I do this? Usually I would just include the script inside the html page, but is there a way to require it directly in the javascript file just like how you can require frameworks in node.js?

Is it possible to use browserify with Meteor.js?

EDIT

FOR Meteor 0.8+

For client only third party libraries

adding your library files in client\\lib folder is enough

For Server side NPM Modules

first add meteorhacks:npm package

It will create packages.json file in root folder

then in that file add your npm packages with exact version numbers,like

{
  "redis": "0.8.2",
  "github": "0.1.8"
}

Then you can use the packages with the following syntaxes

var GithubApi = Meteor.npmRequire('github');
      var github = new GithubApi({
          version: "3.0.0"
      });

      var gists = Async.runSync(function(done) {
        github.gists.getFromUser({user: 'arunoda'}, function(err, data) {
          done(null, data);
        });
      });

      return gists.result;

Documentation for the package https://github.com/meteorhacks/npm

before 0.8

You can include third party libraries by adding the required .js files to clien/lib folder

Then you can use them in your project.

If you want to use npm packages just add

mrt add npm

to your project and you can use like below

This example uses skimlinksjs npm package

var skimlinks = Meteor.require('skimlinksjs');

            skimlinks.setup("xxxx");
            var skimlinks_query = Async.wrap(skimlinks.query);

            var pro_id="productId:\""+s_string+"\"";

            var result = skimlinks_query({
                                searchFor: pro_id,
                                fq: "country:US"
                                });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM