I use the fantastic " browserify ", which works like a charm. This is an alternative to using the Arunda NPM Atmosphere package or using Npm.require with package.js , which may have some advantages:
- My code may use the plain old "require" instead of Npm.require or Meteor.require. Obviously, this is not a huge deal, but if I want to use this code outside of Meteor, it's nice to feel that it is not dependent on Meteor.
- I donβt have to worry about whether Meteor will once again change the way he thinks about integrating into Npm again.
- This allows me to use the local version to develop my own npm modules using the npm link.
Here's how it works:
- I am creating a separate project for npm dependencies in a hidden .npm folder
- I use a browser to create a bundle.js package that will be loaded by a meteorite
- I use gunt watch to make sure bundle.js is updated every time I install a new npm package
Here is my directory structure:
my_meteor_project/ lib/ bundle.js .npm/ node_modules README.md Gruntfile.js entrypoint.js package.json
Here is an example entrypoint.js (unfortunately, I need to use global variables so that assert, url and _ are available in Meteor code)
assert = require('assert'); url = require("url"); _ = require('underscore');
Here's the grunt file:
module.exports = function(grunt) { grunt.initConfig({ watch: { build: { files: ['./entrypoint.js', './package.json'], tasks: ['browserify2'], options: { } } }, browserify2: { compile: { entry: './entrypoint.js', compile: '../lib/bundle.js' } }, }); grunt.loadNpmTasks('grunt-browserify2'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.registerTask('build', ['browserify2']); };
Then I use the grunt clock to view changes in entry.js or new NPM installations
$ cd .npm $ grunt watch:build & [2] 44617 $ Running "watch:build" (watch) task Waiting...
And if I installed the npm module or changed entrypoint.js, bundle.js will update:
$ npm install url -save npm http GET https://registry.npmjs.org/punycode npm http GET https://registry.npmjs.org/querystring npm http 304 https://registry.npmjs.org/punycode npm http 304 https://registry.npmjs.org/querystring url@0.7.9 node_modules/url βββ querystring@0.1.0 βββ punycode@1.0.0 $ OK >> File "package.json" changed. Running "browserify2:compile" (browserify2) task File written to: ../lib/bundle.js Done, without errors. Completed in 1.256s at Thu Jul 11 2013 11:36:22 GMT-0600 (MDT) - Waiting...
Jonathan Warden Jul 11 '13 at 17:48 2013-07-11 17:48
source share