引用Grunt目标导致警告:对象为true没有方法'indexOf'

时间:2013-08-08 22:40:15

标签: gruntjs

我的代码:

'use strict';
module.exports = function(grunt) {

    // Project configuration.
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        //Define paths
        js_src_path:    'webapp/js',
        js_build_path:  'webapp/js',
        css_src_path:   'webapp/css',
        css_build_path: 'webapp/css',
        less_src_path:  'webapp/less',
        less_build_path:'webapp/less',
//Convert Less to CSS and minify if compress = true
        less: {
            development: {
                options: {
                    path: ['<%= less_src_path %>'],
                },
                files: {
                    //'<%= less_build_path %>/app.css':'<%= concat.less.dest %>',
                    //Dynamic expansion 1:1 
                    expand: true,
                    cwd:    '<%= less_src_path %>',
                    dest:   '<%= less_build_path %>',
                    src:    '*.less',
                    ext:    '.less.css'
                }
            },
            production: {
                options: {
                    path: ['<%= less_src_path %>'],
                    //compress: true 
                    yuicompress: true
                },
                files: {
                    //'<%= less_build_path %>/app.css':'<%= concat.less.dest %>',
                    //Dynamic expansion 1:1 
                    expand: true,
                    cwd:    '<%= less_src_path %>',
                    dest:   '<%= less_build_path %>',
                    src:    '*.less',
                    ext:    '.less.min.css'
                }
            }
        }
    });

    // Load the plugin that provides the tasks.
    grunt.loadNpmTasks('grunt-lib-contrib');
    grunt.loadNpmTasks('grunt-contrib-less');

    // Task(s).
    grunt.registerTask('les', ['less']);
    grunt.registerTask('proless', ['less:production']);
    grunt.registerTask('devless', ['less:devevelopment']);
};

运行以下各项:

grunt les
grunt proless
grunt devless

结果:

Warning: Object true has no method 'indexOf' Use --force to continue

如果我删除任务development:{ ... }和'production:{....}'并离开内部,只需将我的les电话更改为点击less就行了。< / p>

1 个答案:

答案 0 :(得分:41)

我遇到了与contrib-concat类似的问题。我认为这是我们两个部分的语法错误。

尝试在开发目标的“files”属性周围添加一个数组文字,如下所示:

 files: [{
                //'<%= less_build_path %>/app.css':'<%= concat.less.dest %>',
                //Dynamic expansion 1:1 
                expand: true,
                cwd:    '<%= less_src_path %>',
                dest:   '<%= less_build_path %>',
                src:    '*.less',
                ext:    '.less.css'
            }]

以下是文档:http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically 希望有所帮助!