2

我正在尝试配置一个可以在多个“主题”上运行多个任务的 grunt 文件。由于我对这整个咕噜声是新手,所以我在配置方面遇到了一些问题。

我下面的示例只是一个开始,但本质上我想要一些全局配置,然后将特定的“主题”配置嵌套在一个命名的“目标”中。我没有完全掌握语法,所以这可能是问题所在,但是当我运行时,grunt powerful我收到错误警告:所需的配置属性“watch”丢失?我觉得配置没问题,但问题出在我的registerMultiTask. 有任何想法吗?

module.exports = function(grunt) {

// Project configuration.

grunt.initConfig({

    // Metadata.
    pkg: grunt.file.readJSON('package.json'),
    banner: '/*!\n' +
        '* Microsites v<%= pkg.version %>\n' +
        '* Copyright <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
        '*/\n' +
        '/* @package: <%= pkg.name %> */\n',
    jqueryCheck: 'if (!jQuery) { throw new Error(\"<%= pkg.name %> requires jQuery\") }\n\n',
    basePath: '../../www/wp-content/themes',

    powerful: {
        name:   'Powerful Theme',
        path:   '<%= basePath %>/powerful',
        less: {
            development: {
                options: {
                    dumpLineNumbers: true
                },
                files: {
                    '<%= powerful.path %>/static/css/project.css':  '<%= powerful.path %>/static/css/less/project.less',
                    '<%= powerful.path %>/static/css/editor.css':   '<%= powerful.path %>/static/css/less/editor.less',
                    '<%= powerful.path %>/static/css/login.css':    '<%= powerful.path %>/static/css/less/login.less'
                }
            },
            production: {
                options: {
                    yuicompress: true
                },
                files: {
                    '<%= powerful.path %>/static/css/project.css':  '<%= powerful.path %>/static/css/less/project.less',
                    '<%= powerful.path %>/static/css/editor.css':   '<%= powerful.path %>/static/css/less/editor.less',
                    '<%= powerful.path %>/static/css/login.css':    '<%= powerful.path %>/static/css/less/login.less'
                }
            },
            ie: {
                options: {
                    yuicompress: true
                },
                files: {
                    '<%= powerful.path %>/static/css/ie.css':       '<%= powerful.path %>/static/css/less/ie.less'
                }
            }
        },
        watch: {
            less: {
                files: ['<%= powerful.path %>/static/css/less/*.less'],
                tasks: ['less:development']
            }
        }
    }, // end: powerful

});


// load the plugin
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');

// load tasks
//grunt.registerTask('default', ['less']);
grunt.registerMultiTask('powerful', 'do things', function(){
    grunt.task.run(['watch']);
});
};
4

1 回答 1

1

任务应该在您的配置的第一级进行,而不是在另一个任务配置中。此外,您的powerful任务不是多任务,因此它甚至不需要配置块。只需以标准方式配置任务:

grunt.initConfig({
  less: {
    /* config here */
  },
  watch: {
    /* config here */
  }
});
于 2013-09-25T23:08:57.550 回答