4

我有一个用 Coffeescript 编写的简单 Gruntfile:

"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"
    ]);

};
4

1 回答 1

2

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

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

希望这会有所帮助。

于 2014-10-20T15:44:11.887 回答