未加星标

Simple build tools: npm scripts vs Makefile vs runjs

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二03 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏
Simple buildtools

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

Cons:

when scripts get complex they are hard to read introducing more complex logic like conditional checks, errors or argument handling can be problematic to implement and maintain you can’t use javascript

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

Cons:

you are tied to shell code, you can’t use JavaScript which you already know this means that sometimes shell code can be hard to deal with. Additional learning curve for complex logic.

Example of Makefile:

Example from https://blog.jcoglan.com/2014/02/05/building-javascript-projects-with-make/

Example of calling a task:

make test runjs Written in JavaScript. Minimalistic build tool. Micro package, it has only around 100 LOC. Can be installed through npm. Allows to define tasks in “runfile.js” file. Tasks can be called by run command in the terminal. [ More ].

Pros:

you can use JavaScript within tasks (with ES6/7) and import other npm modules. runfile.js is just a JavaScript module. This allows massive flexibility . you can do command line calls also, by run function good readability it handles task arguments easily

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操作系统

主题: JavaScriptJavaC++Windows
分页:12
转载请注明
本文标题:Simple build tools: npm scripts vs Makefile vs runjs
本站链接:http://www.codesec.net/view/480557.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(30)