【发布时间】:2014-10-04 09:52:21
【问题描述】:
我最近遇到了load-grunt-tasks 的高效魔力,但我想知道为什么在我见过的大多数示例中,它的使用似乎是例外而不是规则。如果你不熟悉这个模块,它会这样做:
此模块将读取您的 package.json 中的
dependencies/devDependencies/peerDependencies并加载与提供的模式匹配的 grunt 任务。
例如,你的 Gruntfile.js 中的这个混乱:
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-recess');
grunt.loadNpmTasks('grunt-sizediff');
grunt.loadNpmTasks('grunt-svgmin');
// and likely many, many more
...可以用简单的替换:
require('load-grunt-tasks')(grunt);
那么,这种单线有什么缺点吗?如果不是,那为什么它不是在线示例中注册 Grunt 任务的标准呢?我在 SO 或 The Googz 上找不到任何东西,而且对 Node 或 Grunt 也不是很熟悉,因此我将不胜感激。
【问题讨论】:
标签: node.js automation gruntjs npm