[英]Grunt SyntaxError: Unexpected token
I'm trying to use Grunt but I get a SyntaxError. 我正在尝试使用Grunt,但出现SyntaxError。 I can't find the solution. 我找不到解决方案。
MacBook-Pro-van-Maarten:Project maarten$ grunt imagemin Loading "Gruntfile.js" tasks...ERROR MacBook Pro-van-Maarten:项目maarten $ grunt imagemin正在加载“ Gruntfile.js”任务...错误
SyntaxError: Unexpected token ; 语法错误:意外令牌; Warning: Task "imagemin" not found. 警告:找不到任务“ imagemin”。 Use --force to continue. 使用--force继续。 Aborted due to warnings. 由于警告而中止。
Gruntfile.js 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. 看来您的配置无效json。 try usein , instead of ; 尝试用usein代替;
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']);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.