Node packing made easy with grunt

Publish node packages with npm is easier done than said! ;) First of all check out Hitchhikers guide to npm

After which, install grunt! npm install -g grunt and then the fun begins.

Below is a simple example of how to publish node packages with grunt+npm :


$ mkdir test # Replace it with your package name. $ grunt init:node Running "init:node" (init) task This task will create one or more files in the current directory, based on the environment and the answers to a few questions. Note that answering "?" to any question will show question-specific help and answering "none" to most questions will leave its value blank. "node" template notes: Project name shouldn't contain "node" or "js" and should be a unique ID not already in use at search.npmjs.org. Please answer the following: [?] Project name (test) [?] Description (The best project ever.) [?] Version (0.1.0) [?] Project git repository (git://github.com/hemanth/test.git) [?] Project homepage (https://github.com/hemanth/test) [?] Project issues tracker (https://github.com/hemanth/test/issues) [?] Licenses (MIT) [?] Author name (Hemanth.HM) [?] Author email (hemanth.hm@gmail.com) [?] Author url (none) h3manth.com [?] What versions of node does it run on? (>= 0.6.0) [?] Main module/entry point (lib/test) [?] Npm test command (grunt test) [?] Do you need to make any changes to the above before continuing? (y/N) n Writing .npmignore...OK Writing grunt.js...OK Writing lib/test.js...OK Writing README.md...OK Writing test/test_test.js...OK Writing LICENSE-MIT...OK Initialized from template "node". $ tree . ├── LICENSE-MIT ├── README.md ├── grunt.js ├── lib │   └── test.js ├── npm-debug.log ├── package.json └── test └── test_test.js 2 directories, 7 files $ npm publish #Ofcourse, after editing the boiler code as per need.

WISH : Debian packaging was as easy as this!

Built-in tasks As of now, grunt has the following predefined tasks that you can use in your project:

  • concat - Concatenate files.
  • init - Generate project scaffolding from a predefined template.
  • lint - Validate files with [JSHint][jshint].
  • min - Minify files with [UglifyJS][uglify].
  • qunit - Run [QUnit][qunit] unit tests in a headless [PhantomJS][phantom] instance.
  • server - Start a static web server.
  • test - Run unit tests with [nodeunit][nodeunit].
  • watch - Run predefined tasks whenever watched files change.

Happy Hacking! :)

Share this