Rough script for converting a Meteor application into a package

Our largest project was taking ages to refresh (25 seconds) on hot code reload. Turns out a JavaScript file takes about 45ms to load in Chrome on our development machines, JavaScript is loaded synchronously, and we have about 700 client-site JavaScript files. Build time was not a problem.

I noticed that packages get concatenated, where as applications in development do not. So, the solution was to convert the application to a package. Started doing it by hand, was taking forever to order the files. Now, there might already be tools for doing this but if not here’s mine: https://gist.github.com/dj-foxxy/2e6defd2cdbf14afc441

Placed in the root of a Meteor application, it will spit out most of the package.js so that your files load in the same order as Meteor loads them. I didn’t implement everything, just what I needed, but it’s a start (unless something already exists, then it’s a step backwards).

You could also use the --production flag on meteor run to do this too, right? Or were you wanting to avoid minifying the files.

I haven’t got any figures, but we tested --production before we converted to a package and it took just as long. We didn’t investigate why. I’d guess it was increased build time.

Also, I prefer having everything as a package because I like deciding the load order.