简体   繁体   English

您如何在Meteor.js中包含第三方JavaScript库?

[英]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/ ) 在流星中,如果我想使用第三方JavaScript库,例如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? 通常我只将脚本包含在html页面中,但是有没有一种方法可以直接在javascript文件中要求它,就像如何在node.js中要求框架一样?

Is it possible to use browserify with Meteor.js? 是否可以在Meteor.js中使用browserify?

EDIT 编辑

FOR Meteor 0.8+ 对于流星0.8+

For client only third party libraries 对于客户,仅第三方库

adding your library files in client\\lib folder is enough client\\lib文件夹中添加库文件就足够了

For Server side NPM Modules 对于服务器端NPM模块

first add meteorhacks:npm package 首先添加meteorhacks:npm

It will create packages.json file in root folder 它将在根文件夹中创建packages.json文件

then in that file add your npm packages with exact version numbers,like 然后在该文件中添加具有确切版本号的npm软件包,例如

{
  "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 软件包的文档https://github.com/meteorhacks/npm

before 0.8 0.8之前

You can include third party libraries by adding the required .js files to clien/lib folder 您可以通过将所需的.js文件添加到clien/lib文件夹中来包含第三方库。

Then you can use them in your project. 然后,您可以在项目中使用它们。

If you want to use npm packages just add 如果要使用npm软件包,只需添加

mrt add npm

to your project and you can use like below 到您的项目,您可以使用如下所示

This example uses skimlinksjs npm package 这个例子使用skimlinksjs npm包

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"
                                });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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