Reputation: 36930
Meteor has a great file loading policy for general development. It automatically loads files from the app directory with some special treatment for public
, private
, client
and server
directories. (See http://docs.meteor.com/#structuringyourapp)
When loading third-party Javascript libraries into a Meteor app, I usually put them in a <head>
script or directly in the client/compatibility
directory, which works well for released files.
However, sometimes I need to link a developing version of a project directly from a GitHub repository from a certain branch, when testing patches or pull requests. I already do this all the time for Meteor smart packages which are picked up transparently. However, I'm not sure how to do this for general (client-side) Javascript libraries. Moreover, it's the linking in of a repo rather than a listed version that is tricky. Can someone who has had to do this give suggestions?
Upvotes: 1
Views: 811
Reputation: 36930
One approach to this was briefly described in https://github.com/meteor/meteor/issues/1229.
I found that this can be cleanly implemented as a resident smart package in your app. This approach works well in Meteor 0.6.5 and any future versions until this API changes. First create the following in package.js
:
Package.on_use(function (api) {
api.use(['routepolicy', 'webapp'], 'server');
api.add_files('client.html', 'client');
api.add_files('server.js', 'server');
});
and in server.js
, you declare that you want Meteor to serve up an entire directory (the appropriate part of the repo) as part of the app (in my case, OpenLayers):
connect = Npm.require('connect');
RoutePolicy.declare('/lib', 'network');
WebApp.connectHandlers
.use(connect.bodyParser())
.use('/lib', connect.static("/home/mao/projects/openlayers/lib"));
finally, client.html
tells your app to load up the code in the right path:
<head>
<script src="/lib/OpenLayers.js"></script>
</head>
Assuming the above package was in a directory named openlayers
, commenting or uncommenting openlayers
in the package
file of my app allows me to switch really easily between compiled releases and running from repo for this package.
Upvotes: 1