【发布时间】:2015-03-30 01:10:30
【问题描述】:
我正在尝试使用 load-grunt-config 将我相当大的 Grunt 文件拆分为几个较小的部分。我在项目的根目录中有一个 Gruntfile.js,在一个名为 grunt 的目录中有子任务。
这是我的 Gruntfile.js:
module.exports = function(grunt) {
require('load-grunt-config')(grunt, {
loadGruntTasks: {
pattern: '*',
config: require('./bower.json'),
scope: 'devDependencies'
}
});
};
例如,这是我的 grunt/copy.js 文件:
module.exports = function (grunt) {
return {
main: {
files: [{
cwd: 'init/php/templates',
src: '<%= init.php.templates %>',
dest: 'src/php/templates',
expand: true
}],
options: {
process: function (content, srcpath) {
return grunt.template.process(content);
}
}
}
}
};
无论我尝试什么(包括将 copy.js 文件重命名为 grunt-copy.js),Grunt 总是抱怨它无法找到我的任务。我收到此错误消息:
Warning: Task "copy:main" not found. Use --force to continue.
我在这里咬花岗岩。一定有问题,但我真的不知道是什么,所以任何提示都表示赞赏。
【问题讨论】:
-
您是否尝试过让基本版本正常工作?也许只有一项没有额外配置的任务:
require('load-grunt-config')(grunt);?也许简化你复制任务配置只是为了看看问题是你的配置还是 load-grunt-config 插件。 -
愚蠢的我,效果很好。原来问题出在 loadGruntTasks 部分。我使用它来将我的安装任务指向正确的 bower.json,因为现在它需要 grunt 文件夹中的一个 bower.json 和根目录中的一个。使用配置我解决了这个问题,但显然这会导致任务崩溃。现在我需要找到一种只使用一个 bower.json 的方法;)
-
很高兴你至少找到了一部分!
标签: javascript node.js configuration gruntjs task