gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:45:00 27 4
gpt4 key购买 nike

最近在结识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 thetwo.
  • Cross platform JavaScript.
  • Package Managers: An Introductory Guide For The Uninitiated Front-EndDeveloper.
  • 关于makefile - 什么是生成文件?它与 Gruntfile 或 npm run 有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24486306/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com