1

Does anyone have experience managing the build process for a smart package, so that external files can be downloaded and served?

For example, a meteor smart package the wraps a javascript library can curl the library when the app is being built, and serve it directly from the server. This is useful for things like jquery-ui, the Ace editor, etc.

Specifically, I'm asking about the proper way to use Package._transitional_registerBuildPlugin, which was introduced in 0.6.5. Any examples would be great.

Grepping Meteor code only turns up things that add source handlers, so it's not very helpful for deciding what to do for downloading a file.

./packages/templating/package.js:Package._transitional_registerBuildPlugin({
./packages/stylus/package.js:Package._transitional_registerBuildPlugin({
./packages/meteor/package.js:Package._transitional_registerBuildPlugin({
./packages/coffeescript/package.js:Package._transitional_registerBuildPlugin({
./packages/less/package.js:Package._transitional_registerBuildPlugin({

A related question: what is a smart package allowed to write to its own .build folder?

3
  • Could you just use a git submodule and add the file using a regular api.add_files call?
    – sbking
    Nov 20, 2013 at 20:11
  • Can you explain why do you need this to be a part of the build process? You can always dynamically load javascript code on demand with simple AJAX requests, so what's wrong with this strategy? Nov 20, 2013 at 21:00
  • @apendua because I want the Meteor server to serve the file to each client, instead of external CDNs, which also allows me to control the load order.
    – Andrew Mao
    Nov 20, 2013 at 21:56

2 Answers 2

0

I am aware that this is not exactly an answer for your question, but I couldn't resist posting this idea :)

The easiest thing that comes to my mind is to implement a simple "proxy" server using curl as you suggested. It could be more or less something like:

var spawn = Npm.require('child_process').spawn;

WebApp.connectHandlers.stack.splice (0, 0, {
  route: '/jquery.js',
  handle: function(req, res, next) {
    spawn('curl', [
        'https://code.jquery.com/jquery-1.10.2.min.js'
      ]).stdout.pipe(res);
    res.writeHead(200, {
      'Content-Type': 'text/javascript'
    });
  },
});

Though, it does not solve - out of the box - the problem of controlling the load order.

EDIT

If you prefer not to call curl every single time the file is requested by the user, you can always cache it somewhere on the server, right? Also this technique allows you to load additional libraries on demand, so only when they're actually needed. Note, that things like ace editor can be pretty heavy.

1
  • Hi @apendua, what's the point of doing this compared to asking the client to retrieve the file directly? I want to retrieve the file once during the build process, then serve it out to the client along with other packages in the proper order.
    – Andrew Mao
    Nov 21, 2013 at 4:28
0

I ended up implementing this as a build plugin as part of my ShareJS smart package.. It's not the prettiest thing, but does what it needs to do. My approach is leading toward a generalized smart package for processing CDN downloads from Meteor packages.

I expect that the path to doing things like this will become easier and clearer as the build API becomes better documented.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.