2016-03-01 48 views
0

我想分割成小片大gruntfile来到这些文章: https://github.com/firstandthird/load-grunt-config http://ericnish.io/blog/how-to-neatly-separate-grunt-files/ 但是,似乎我失去了一些东西明显。当我发出“grunt testtask”时,找不到任务。显然,我正在做一些非常错误的事情,但我不明白。 这里的文件的内容,精简尽可能:负载咕噜-Config中找不到目标任务

gruntfile.js: 
module.exports = function(grunt) { 
var path = require('path'); 

require('load-grunt-config')(grunt, { 
    configPath: path.join(process.cwd(), 'grunt3'), 
     init: true 
    }); 
}; 

grunt3/testtask.js: 
module.exports = { 
    copy: { 
    main: 
    { 
     files: 
     [{ 
      src: "test1.txt", 
      dest: "test2.txt" 
     }] 
    } 
    } 
}; 

I added an aliases file: 
module.exports = { 
    'default': [], 
    'mytesttask': [ 
    'testtask' 
    ] 
}; 

默认被发现。对于mytesttalk,我会得到“testtask not found”。 不应该aliases.js为文件名(testtask)或“复制”(我也尝试使用'复制'作为目标任务)做一个registerTask? 根据--config-debug,有一个名为“testtask”的配置对象。 我在这里错过了什么?

谢谢。

附录:在同一主题上发现了这个非常简单和直接的文章,它展示了如何进一步简化。再一次,它不起作用。未找到在别名中指定的任务。例如'mytesttask':['testtask'] - > testtask没有找到,尽管有一个grunt/testtask.js文件包含来自原始gruntfile的任务。我错过了什么?

回答

1

在这篇优秀的文章http://mattbailey.io/a-beginners-guide-to-grunt-redux.html的帮助下,该模块的作者之一评论github,我终于找到了我思考中的缺陷。这些文件不是由任务或目标组织的,而是由grunt模块组织的。所以,你必须将它们命名为copy.js(来自grunt-contrib-copy),cssmin.js(来自grunt-contrib-cssmin),concat.js(来自grunt-contrib-concat),并将各种目标放在这些文件。而不是相反(正如我所想的那样)。也许从文档中可以清楚地看到其他人,这不适合我。 Matt Bailey发表的文章非常棒,因为它只显示了真正必要的内容。我上面引用的Eric Nishio的文章不必要的复杂,因为它没有考虑别名文件。