makefile - 什么是生成文件?它与 Gruntfile 或 npm run 有何不同?

标签 makefile gruntjs npm

最近在结识Mocha javascript testing framework的同时,我遇到了这个我不明白的部分:

Makefiles

Be kind and don't make developers hunt around in your docs to figure out how to run the tests, add a make test target to your Makefile:


test:
    ./node_modules/.bin/mocha --reporter list

.PHONY: test

这几乎没有描述性,如果您不知道 makefile 是什么,也不是很有帮助。

那么,什么是 Makefile?它与 Gruntfile 或使用 npm run 有何不同? ?

最佳答案

生成文件

Makefile(通常没有文件扩展名)是 Unix 使用的配置文件 make工具。

引自 best introductions I have found on Make 之一如果您有兴趣了解更多有关 make 和一般任务运行器的信息,我强烈建议您阅读。

Make is the original UNIX build tool. It existed a long time before gulp, or grunt. Loved by some, loathed by others it is at least worth being aware of how make works, what the strengths are and where it falls short.

Make is available on UNIX-like systems. That means OSX, BSD and Linux. It exposes any system command meaning that you can run system commands and execute arbitrary scripts. There is no doubt that tools like gulp and grunt are inpsired by or at least a reaction to make.

To use make you create a Makefile and then run make [what to run] from the terminal.



Gruntfile.js

Gruntfile.js 是 Grunt.js 使用的 javascript 配置文件工具。

如果你愿意,更新的 node.js 版本是 Grunt.js,它是跨平台的(适用于 Windows)并用 Javascript 编写。两者都可以做类似的事情,比如连接文件、缩小 css、运行测试等。网上有很多关于 Grunt 的信息。

'npm 运行'

一些开发人员更喜欢使用的另一个选项是 npm 本身,使用 npm run命令如本 informative post on how to use npm run for running tasks 中所述:

There are some fancy tools [Grunt] for doing build automation on javascript projects that I've never felt the appeal of because the lesser-known npm run command has been perfectly adequate for everything I've needed to do while maintaining a very tiny configuration footprint.

If you haven't seen it before, npm looks at a field called scripts in the package.json of a project in order to make things like npm test from the scripts.test field and npm start from the scripts.start field work.

npm test and npm start are just shortcuts for npm run test and npm run start and you can use npm run to run whichever entries in the scripts field you want!



其他不错的介绍性资源:
  • Introduction to grunt.js and npm scripts, and choosing between the two.
  • Cross platform JavaScript.
  • Package Managers: An Introductory Guide For The Uninitiated Front-End Developer.
  • 关于makefile - 什么是生成文件?它与 Gruntfile 或 npm run 有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24486306/

    相关文章:

    node.js - 意外的 token 非法 - Istanbul 尔测试_mocha

    socket.io - 在 Windows 上安装 socket.io 时出错

    typescript - 使用 ES6 集合类型创建和发布 NPM 模块

    c - 这个 Makefile 有什么问题?

    python - 尝试在 ubuntu windows 中查看输出时出现 Makefile 错误

    node.js - 在 Heroku 上运行预部署 Grunt 任务

    javascript - 我可以有多个 Grunt 文件吗

    javascript - 没有根文件夹的 Grunt Compress

    makefile - 进入额外目录

    variables - Makefile 中的括号 $() 和大括号 ${} 语法有什么区别?