简体   繁体   中英

Grunt SyntaxError: Unexpected token

I'm trying to use Grunt but I get a SyntaxError. I can't find the solution.

MacBook-Pro-van-Maarten:Project maarten$ grunt imagemin Loading "Gruntfile.js" tasks...ERROR

SyntaxError: Unexpected token ; Warning: Task "imagemin" not found. Use --force to continue. Aborted due to warnings.

Gruntfile.js

module.exports = (function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON("package.json"),
    imagemin: {
      png: {
        options: {
          optimizationLevel: 7
        },
        files: [
          {
            expand: true,
            cwd: 'images_src/',
            src: ['**/*.png'],
            dest: 'images_imagemin',
            ext: '.png'
          }
        ]
      };
      jpg: {
        options: {
          progressive: true
        },
        files: [
          {
            expand: true,
            cwd: 'images_src/',
            src: ['**/*.jpg','**/*.jpeg'],
            dest: 'images_imagemin/',
            ext: '.jpg',
          }
        ]
      };
    };
  });
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  grunt.registerTask('default', ['imagemin']);
});

Thanks in advance.

It looks like your config is not valid json. try usein , instead of ;

module.exports = (function (grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON("package.json"),
    imagemin: {
      png: {
        options: {
          optimizationLevel: 7
        },
        files: [
          {
            expand: true,
            cwd: 'images_src/',
            src: ['**/*.png'],
            dest: 'images_imagemin',
            ext: '.png'
          }
        ]
      },
      jpg: {
        options: {
          progressive: true
        },
        files: [
          {
            expand: true,
            cwd: 'images_src/',
            src: ['**/*.jpg', '**/*.jpeg'],
            dest: 'images_imagemin/',
            ext: '.jpg',
          }
        ]
      },
    },
  });
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  grunt.registerTask('default', ['imagemin']);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM