Tasks are simply added to your project’s
package.json like this:
npm run <scriptname> into your Terminal. For the most commonly run script,
test, you can even just type:
By using the back-tick ` and
npm run‘s silent mode you can even pass information from task to task:
Here I am using
npm run jshint and
npm run lintspaces.
It comes with support for JSHint, Browserify, and more – in fact because it works any tool that has a command line interface directly it supports everything! And you can say goodbye to installing
If you haven’t guessed by now this post is intentionally a little bit tongue-in-cheek and provocative – but it is also a serious suggestion and I’m not the first person to suggest it.
npm scripts as your task runner has a number of quite compelling advantages:
- If you have node, npm scripts is already installed.
- With npm scripts you will have fewer dependencies because you install tools directly rather than the task-runner specific version of each tool, which makes them quicker to install and easier to update.
- Reduces the number of files in your repositories (no need for an additional Gruntfile, Gulpfile, etc)
One obvious downside is that for complex projects the scripts section of your
package.json files will start to get a little crowded. But for those cases there’s a natural upgrade path to make…
* This might be a lie.