javascript - Gruntfile.js 任务...错误

标签 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”

最佳答案

由于某种原因,您在文件中添加了一些额外的文本。它应该以 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']);

}

关于javascript - Gruntfile.js 任务...错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27257698/

相关文章:

javascript - 如何将 javascript 变量设置为静态 json 数据?

javascript - 单击复选框时禁用/启用输入 jQuery

javascript - 如何在正则表达式中向密码验证添加特殊字符

javascript - grunt.js - 将 javascript 连接到函数调用中

node.js - 通过 grunt 在实时服务器上运行 Protractor

javascript - PhoneGap/Cordova 在 Safari 中打开外部链接,而不是在 App 中全屏显示

node.js - 由于 Node.js 和 Angular 运行在不同的本地主机上,如何在 Angular 中使用 Nodemailer 电子邮件验证的路由?

mongodb - mongoose node.js,使用 $lt 和 $gt 查询不工作

php - 在 php 中处理实时通知的最佳方法是什么?

node.js - Grunt 不返回任何内容