Jason Ip
Jason Ip

Reputation: 353

JS plugins, ok for Meteor?

I'm trying to incorporate a Twitter Bootstrap template with Meteor and I'm having trouble understanding how I should include files. For example, let's start with Bootstrap itself, should I install it with Meteor/Meteorite or do it manually with script includes? Same for other javascript plugins (e.g. jquery <- this one is builtin to Meteor right?, lightbox.js.. etc.)

Hope I'm making sense, thanks!

Upvotes: 0

Views: 160

Answers (2)

user2139950
user2139950

Reputation: 101

The most common libraries such as jQuery and Bootstrap (v2.3.0) are provided by the Meteor core (v0.6.6.3). They can be listed using meteor list and included with meteor add.

As referred before, Atmosphere is a collection of unofficial Meteor packages giving an easy way with Meteorite to include even 3rd party solutions to your own project.

Moreover, you should learn the Meteor App structure. Directories created on your project have different preferences in terms of files visibility and loading order. I recommend reading Ritik Malhotra's presentation about the App structure at http://www.slideshare.net/RitikM/building-a-production-ready-meteor-app. There's also a Youtube video about his presentation that can be watched here http://www.youtube.com/watch?v=gfFGjmiKfnA.

Upvotes: 0

Tarang
Tarang

Reputation: 75955

By default meteor already includes jquery.

It's best to look to get your plugins installed via Meteorite. So something like this could get you started

sudo -H npm install -g meteorite

Then in your project directory

mrt add bootstrap-3

For other plugins you can't find on atmosphere add the files into a directory in your project /client/lib. Meteor will automatically reference the files for you, both css and js.

This way they only run on the client side and are loaded first. (such as lightbox.js)

You might have to modify a few files with Meteor, though. In meteor each file's variables are file-scoped. So you can't access them from other files. (meteor basically throws a (function() {..}).call() around the code.

So if you get some kind of issue about a variable being undefined look for the variable and remove the var keyword and remove it so that the variable/method becomes global. With jquery plugins this usually isn't a problem.

Most that have the variable scoping issues are on http://atmosphere.com so you shouldn't run into too many problems.

Upvotes: 1

Related Questions