【问题标题】:Gruntfile.js tasks... ERRORGruntfile.js 任务...错误
【发布时间】:2014-12-02 19:48:35
【问题描述】:

试图让 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”

【问题讨论】:

    标签: javascript node.js gruntjs npm


    【解决方案1】:

    由于某种原因,您在文件中添加了一些额外的文本。它应该以module.exports 开头,最后还有一些额外的东西。

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

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

    【讨论】:

    • 很好,更新原因。如前所述,看起来您已将 gruntcode 粘贴到类似于 package.json sn-p 的内容中。
    猜你喜欢
    • 2016-03-02
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多