简体   繁体   English

如何在流星应用程序中包含外部JS库?

[英]How do I include an external JS lib in a meteor app?

I have a basic bootstrap page set up using the Meteor JS framework. 我有一个使用Meteor JS框架设置的基本引导页面。

I've followed this tutorial: 我遵循了本教程:

http://www.manuel-schoebel.com/blog/meteorjs-and-twitter-bootstrap---the-right-way http://www.manuel-schoebel.com/blog/meteorjs-and-twitter-bootstrap---the-right-way

I want to use Jcrop (an external JS lib): 我想使用Jcrop(外部JS库):

http://deepliquid.com/content/Jcrop.html http://deepliquid.com/content/Jcrop.html

In the bootstrap file I only need to include the body element and the content. 在引导文件中,我只需要包含body元素和内容。 How do I include this JS source, and any other required lib? 如何包含此JS源以及任何其他必需的lib? Usually I'd just reference the lib in the html page. 通常我只是在html页面中引用lib。 Does Meteor magically handle this in some way? 流星以某种方式神奇地处理了这个吗?

Thanks again in advance for any pointers. 再次感谢您的任何指点。

The easiest way is to use mrt . 最简单的方法是使用mrt I've used this package before and it worked like a charm. 我以前使用过这个包,它像一个魅力。

mrt add jquery-jcrop

Otherwise, you can download jcrop and put jquery.Jcrop.min.js somewhere in your source tree. 否则,您可以下载jcrop并将jquery.Jcrop.min.js放在源代码树中的某个位置。 Meteor will automatically create the script tag for you so you do not need to change your html. 流星会自动为您创建脚本标签,因此您无需更改html。

The only trick is making sure that its dependencies are loaded, which is what the mrt package does. 唯一的技巧是确保已加载其依赖项,这就是mrt包所做的事情。

With JCrop you can use meteorite to add it in: 使用JCrop,您可以使用陨石将其添加到:

mrt add jquery-jcrop

If you cant find the package on atmosphere you can add the files into a folder in /client/compatibility . 如果找不到大气中的软件包,则可以将文件添加到/client/compatibility的文件夹中。 It's usually simple if you have a minified file. 如果您有一个缩小的文件,这通常很简单。 This directory is slightly special, since Meteor won't apply variable scoping to files in it. 此目录有些特殊,因为Meteor不会对其中的文件应用变量作用域。

For others with multiple files, file loading order is important and you would have to make a package for it. 对于其他具有多个文件的文件,文件加载顺序很重要,因此您必须为其打包

Meteor will automatically reference the file so you can just start using it. 流星会自动引用该文件,因此您可以开始使用它。 For most Jquery plugins, such as JCrop, you can use the Template's rendered callback to instantiate the element on the template. 对于大多数Jquery插件(例如JCrop),您可以使用Template的呈现的回调来实例化模板上的元素。

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

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