Gruntfile.js任务......错误

时间:2014-12-02 19:48:35

标签: javascript node.js gruntjs npm

试图让Grunt将我的CSS文件连接成一个名为production.css的文件

以下是命令提示符

的输出
C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test>grunt

C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test\Gruntfile.js:2
  "name": "AjaxPmodule.exports = function(grunt) {
        ^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected token :
Warning: Task "default" not found. Use --force to continue.

Aborted due to warnings.

C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test>grunt

C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test\Gruntfile.js:2
  "name": "AjaxPmodule.exports = function(grunt) {
        ^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected token :
Warning: Task "default" not found. Use --force to continue.

Aborted due to warnings.

C:\Users\josha\Desktop\Repos\AJAX Project - Grunt Test>

这是我的Gruntfile

{
  "name": "AjaxPmodule.exports = function(grunt) {

    // 1. All configuration goes here 
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

concat: {   
    dist: {
        src: [
            'css/*.css', // All JS in the libs folder
        ],
        dest: 'css/production.css',
    }
}

    });

    // 3. Where we tell Grunt we plan to use this plug-in.
    grunt.loadNpmTasks('grunt-contrib-concat');

    // 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
    grunt.registerTask('default', ['concat']);

};roject",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-concat": "^0.5.0"
  }
}

我使用grunt-contrib-concat来连接我的文件。版本是" ^ 0.5.0"

1 个答案:

答案 0 :(得分:1)

您出于某种原因在文件中添加了一些额外的文字。它应该从module.exports开始,最后你还有一些额外的东西。

我认为您所做的基本上是将您的grunt代码粘贴到类似于package.json的代码段中:

{
   "name": "ajaxProject",
   "version": "0.1.0",
   "devDependencies": {
      "grunt": "~0.4.1",
      "grunt-contrib-concat": "^0.5.0"
   }
}

试试这个:

module.exports = function(grunt) {

    // 1. All configuration goes here 
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        concat: {   
            dist: {
                src: [
                    'css/*.css', // All JS in the libs folder
                ],
                dest: 'css/production.css',
            }
        }

    });

    // 3. Where we tell Grunt we plan to use this plug-in.
    grunt.loadNpmTasks('grunt-contrib-concat');

    // 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
    grunt.registerTask('default', ['concat']);

}