Reputation: 1
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.
Upvotes: 0
Views: 1848
Reputation: 197
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']);
});
Upvotes: 0