Grunt参考错误

时间:2014-08-05 10:48:15

标签: node.js gruntjs grunt-contrib-concat grunt-cli

Gruntfile.js

   module.exports = functions(grunt)
    {
     grunt.initConfig({
   //pkg: grunt.file.readJSON('package.json'),
     concat: {
    options: {
        separator: ';',
    },
       dist: {
        src:   ['APIdocu/AccountsCollection.md', 'APIdocu/AccountsFollowersCollection.md'],
    dest: 'APIdocu/ConcatApis.md',
        //files: {
            //'APIdocu/NewApi.md' : ['APIdocu/AccountsCollection.md', 'APIdocu/AccountsFollowersCollection.md']
        },
},
});

grunt.loadNpmTasks('grunt-contrib-concat');
//tasks
grunt.registerTask('default', ["concat"]);
 }

错误消息

Initializing
Command-line options: --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Loading "Gruntfile.js" tasks...ERROR
ReferenceError: grunt is not defined
at Object.<anonymous> (C:\Users\gs1460\Desktop\Markdownfiles\apis\Gruntfile.js:1:90)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at loadTask (C:\Users\gs1460Desktop\Markdownfiles\apis\node_modules\grunt\lib\grunt\task.js:323:10)
at Task.task.init (C:\Users\gs1460\Desktop\Markdownfiles\apis\node_modules\grunt\lib\grunt\task.js:437:5)
at Object.grunt.tasks (C:\Users\gs1460\Desktop\Markdownfiles\apis\node_modules\grunt\lib\grunt.js:120:8)
at Object.module.exports [as cli] (C:\Users\gs1460\Desktop\Markdownfiles\apis\node_modules\grunt\lib\grunt\cli.js:38:9)

    Running tasks: concat:dist
    Warning: Task "concat:dist" not found. Use --force to continue.
    Aborted due to warnings.

如何摆脱此错误。 我需要将md文件连接到一个。它给我上面的错误。尝试多次更改代码。但同样的问题。你能帮忙吗?

1 个答案:

答案 0 :(得分:0)

问题可能是您正在撰写functions而不是function。 还要检查变量grunt是否在正确的范围内。请正确使用标签!

module.exports = function(grunt)

问候。