Pros and Cons of `npm scripts` vs Gulp
npm scripts vs Gulp
npm scripts are low-level and leverage the actual library you want to use (example:
"lint": "eslint ./")
package.json is a central place to see what scripts are available (also
npm run will list all scripts)
- When things get too complicated you can always defer to another file (example:
"complex-script": "babel-node tools/complex-script.js")
npm scripts are more powerful than one might first think (pre/post hooks, passing arguments, config variables, chaining, piping, etc...)
- We aren't tied to a specific build abstraction (Anvil, brocolli, Grunt, Gulp) when the next big thing comes out.
- Not everyone is familiar with
- Some scripts can get lengthy and cumbersome
npm-run-all: A CLI tool to run multiple npm-scripts in parallel or sequential.
rimraf: A deep deletion module for node (like
onchange: Use glob patterns to watch file sets and run a command when anything is added, changed or deleted.
- There are lots of Gulp plugins and utilities
- We already have some helper libraries to provide common Gulp tasks
Thoughts to Consider
- Gulp plugins often get out of date and don’t support new features from the underlying library
- You become dependant on the Gulp plugin author and not the library that is being wrapped
- Documentation for Gulp plugins are typically not very robust or comprehensive
- Debugging a Gulp plugin can be frustrating. Is the problem in the plugin or in the underlying library?
- If a plugin doesn't exist already for Gulp you need to write it yourself
- Errors that occur inside a Gulp wrapper arean't always handled very well
- Do we switch to
npm scripts only, keep using Gulp, or have a mixture of the two?
- If we have a mixture of
npm scripts and Gulp, how do we decide when to use what? Do we start with an assumption of
npm scripts until a certain complexity threshold is met? Do we only use
npm scripts for new projects and then split out to
tools/script-file.js when the complexity gets high? (See react-slingshot for an example)
- How do we reconcile projects that have Gulp already in them? Do we keep updating them or do we consider switching them to
npm scripts if we find we keep updating them?