Command line based build tools gain a lot of attention in the JavaScript world recently. They are straightforward, flexible and quite easy to manage compare to verbose Grunt.js/Gulp.js files and workflows. This goes with the way of being agile and adaptable which is more and more important in the fast changing JavaScript world. But which command line based build tool to choose ? What’s the differences between them ?
Main disadvantages:
Further reading:
Why we should stop using Grunt & Gulp_If you're building a modern JavaScript application or website, there's a good chance you've seen the JavaScript Build…_www.keithcirkel.co.uk
Why I Left Gulp and Grunt for npm Scripts_I know what you’re thinking. WAT?! Didn’t Gulp just kill Grunt? Why can’t we just be content for a few minutes here in…_medium.freecodecamp.com
We have 3 candidates: npm scripts, Makefile and runjs. All of those are based on command line scripting. You don’t need much of knowledge about those tools. They are very easy with their construction and workflow. What is important is how you can effectively manage command line scripts.
Main advantages:
Built-in feature into npm package manager. Content of each task is held in package.json under “scripts” section. Each task can be called by npm run [task-name] command. [More].
Pros:
Cons:
Obviously you can reduce those cons by extracting commands from scripts section to separate files (bash/node scripts) and call them in npm scripts. In the end it’s not necessary convenient though as you will have your build code spread out across multiple files. For tasks up to 15/20 lines of code which are quite frequent it can feels just too much. Moreover if you want to use ES6/7, ES6 imports in your node.js build scripts you need to compile them. That complicate the process unnecessary.
Example of npm scripts usage:
Example of calling a task:
npm run watch:test
Build automation tool created by Stuart Feldman and initially released in 1977. With the main purpose for C/C++ code compilation. However thanks to its flexibility it started to gain more universal usage. It allows to define tasks in “Makefile” file. Tasks can be called by make command in the terminal. [More].
Pros:
Cons:
Example of Makefile:
Example of calling a task:
make test
Written in JavaScript. Minimalistic build tool. Can be installed through npm. Allows to define tasks in “runfile.js” file. Tasks can be called by run (or npx run) command in the terminal. [More].
Pros:
Cons:
Example of runfile.js:
Example of calling a task:
run testrun lint components/App.js --fixrun build:clean
I would say that considering the simple build tooling, all of those 3 are really good. The main difference is within the relation between flexibility and readability. In that matter runjs seems to be the strongest.
For further experimenting I give you a couple of interesting examples which are easy to do in runjs but can be hard to manage in npm scripts or Makefile.
Documenting tasks:
$ run build --help
Sharing tasks to a npm package:
$ run shared
Accepting arguments and conditional checks:
$ run test sidebar/button.js browser
Error handling and fallbacks:
$ run build
Handling async calls:
$ run start