Grunt中“验证属性___存在于配置中”是什么意思?

时间:2014-10-20 15:18:45

标签: coffeescript gruntjs grunt-contrib-copy

我有一个用Coffeescript编写的简单Grunt文件:

"use strict"

module.exports = (grunt) ->

    config =
        src: "app"
        dist: "build"

    grunt.initConfig =
        config: config
        copy:
            dist:
                files: [
                    expand: true
                    cwd: "<%= config.app %>"
                    dest: "<%= config.dist %>"
                    src: [
                        "*.{ico,png}"
                        "{*/}*.html"
                    ]
                ]

    grunt.loadNpmTasks "grunt-contrib-copy"

    grunt.registerTask "build", [
        "copy:dist"
    ]

    grunt.registerTask "default", [
        "build"
    ]

运行时会抛出以下错误:

Verifying property copy.dist exists in config...ERROR
>> Unable to process task.
Warning: Required config property "copy.dist" missing. Use --force to continue.

这也是指什么?似乎copy.dist存在,为什么它没有被阅读?

另外,我认为这是一个Coffeescript格式问题,因为用Javascript编写的等效Gruntfile不会引发这个问题:

"use strict";

module.exports = function (grunt) {

    // Configurable paths
    var config = {
        scr: "app",
        dist: "build"
    }

    grunt.initConfig({

        // Project settings
        config: config,

        copy: {
            dist: {
                files: [{
                    expand: true,
                    cwd: "<%= config.app %>",
                    dest: "<%= config.dist %>",
                    src: [
                        "*.{ico,png}",
                        "{*/}*.html"
                    ]
                }]
            }
        }
    });

    // Install plugins
    grunt.loadNpmTasks("grunt-contrib-copy");

    grunt.registerTask("build", [
        "copy:dist"
    ]);

    grunt.registerTask("default", [
        "build"
    ]);

};

1 个答案:

答案 0 :(得分:2)

我在配置块中看不到config.app,我只能看到包含字符串("app")的config.src。

所以我会尝试将cwd: "<%= config.app %>"换成cwd: "<%= config.src %>"

希望这会有所帮助。