module.exports = function(grunt){
'use strict';
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
//Lint JavaScript (validate JS)
jshint: {
all: {
options: {
force: true
},
src: ['Gruntfile.js', 'source/js/*.js', 'source/views/js/*.js']
}
},
// Lint CSS (validate CSS)
csslint: {`enter code here`
lax: {
options: {
force: true
},
src: ['source/css/*.css', 'source/views/css/*.css']
}
},
//Clean and New folder for optimized code
clean: {
dev: {
src: ['dest/'],
},
},
mkdir: {
dev: {
options: {
create: ['dest/']
},
},
},
//Copy thee files in 'dest' folder
copy: {
main: {
files: []
{expand: true, cwd: 'source/', src: ['**'], dest: 'dest/'}
],
},
},
//JS Minification
uglify: {
my_target: {
files: [{
expand: true,
cwd: 'dest/js',
src: ['*.js'],
dest: 'dest/js'
},{
expand: true,
cwd: 'dest/views/js',
src: ['*.js'],
dest: 'dest/views/js'
}]
}
},
//CSS Minification
cssmin: {
target: {
files: [{
expand: true,
cwd: 'dist/css',
src: ['*.css'],
dest: 'dist/css',
ext: '.css'
},{
expand: true,
cwd: 'dist/views/css',
src: ['*.css'],
dest: 'dist/views/css',
ext: '.css'
}]
}
},
// resize images from pizza
responsive_images: {
dev: {
options: {
engine: 'im',
sizes: [{
width: 77,
quality: 60
},{
width: 116,
quality: 60
},{
width: 232,
quality: 60
},{
width: 720,
quality: 60
}]
},
files: [{
expand: true,
src: ['**.{gif,jpg,png}'],
cwd: 'dest/views/images/',
dest: 'dest/views/images/'
}]
}
}
});
grunt.registerTask('default', [
'jshint',
'csslint',
'clean',
'mkdir',
'copy',
'uglify',
'cssmin',
'responsive_images'
]);
};
在命令提示符中运行grunt会出现ERROR:
正在加载" gruntfile.js"任务...错误>> SyntaxError:意外的令牌 警告:任务"默认"未找到。使用--force继续。
我不知道我哪里出错了。任何帮助都会得到赏识!
答案 0 :(得分:1)
你的grunt文件中有拼写错误。
更改
// ... config before
copy: {
main: {
files: []
{expand: true, cwd: 'source/', src: ['**'], dest: 'dest/'}
],
},
},
// ... config after
要:
// ... config before
copy: {
main: {
files: [ //removed array close
{expand: true, cwd: 'source/', src: ['**'], dest: 'dest/'}
]
}
},
// ... config after