Simple build tools: npm scripts vs Makefile vs runjs
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 :shallow learning curve easy customisation, flexibility plugins are not needed, cli commands are powerful enough npmscripts 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:you don’t need to install additional tools, npm scripts are part of npm, so you are ready to go right away hook scripts, which can be run in specific situations, like prepublish , postinstall or pretest
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 from https://www.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/
Example of calling a task:npm run watch:test Makefile 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:implementing more complex logic is not an issue good readability you don’t need to install additional tools (unless you are windows user), make should be already present in the unix environment
Example of Makefile:
Cons:needs to be installed?
Example of runfile.js :
Example of calling a task:run test Conclusions
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 is 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 .
本文系统（linux）相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统
本文标题：Simple build tools: npm scripts vs Makefile vs runjs