Pergunta

Aqui está meu Gruntfile.js

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),

        uglify: {
          options: {
            mangle: true
          }
          build: {
            src: "js/*.js",
            dest: "js/min/script.js"
          }
        }

    });

    grunt.loadNpmTasks("grunt-contrib-uglify");

    grunt.registerTask('default', [uglify]);

};

Aqui está meu package.json - eu executei npm install já, com todos os plugins que irei usar no meu Gruntfile, grunt-contrib-uglify está entre eles.

{
  "name": "bootbuckle",
  "version": "0.1.0",
  "engines": {
    "node": ">= 0.10.0"
  },
  "devDependencies": {
    "grunt": "~0.4.2",
    "grunt-contrib-watch": "~0.5.3",
    "grunt-contrib-sass": "~0.6.0",
    "grunt-csscomb": "~2.0.1",
    "grunt-contrib-htmlmin": "~0.1.3",
    "grunt-contrib-imagemin": "~0.4.1",
    "grunt-contrib-uglify": "~0.2.7"
  }
}

Quando eu simplesmente corro grunt no terminal - aqui está o erro

  build: {
  ^^^^^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected identifier
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.

Agradecemos antecipadamente por qualquer ajuda que você possa fornecer.


Editar seguindo a orientação de Matti que inseri uma vírgula ausente, um novo erro agora está sendo jogado

Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: uglify is not defined
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
Foi útil?

Solução

Você perdeu uma vírgula aqui:

    uglify: {
      options: {
        mangle: true
      }, // <-------
      build: {
        src: "js/*.js",
        dest: "js/min/script.js"
      }
    }

Editar:conforme postado por japrescott, você deve definir a tarefa uglify como string.

grunt.registerTask('default', ["uglify"]);

Outras dicas

tente assim

  grunt.registerTask('default', ["uglify"]);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top