正如标题中所提到的,它发生在我运行Grunt时,我无法弄清楚我的代码有什么问题。我用JShint检查它,没有错误。
function () {
'use strict';
}
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: 'rn'
},
dist: {
src: ['development/js/**/*js'],
dest: 'development/js/compiled.js'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */n'
},
dist: {
files: {
'dist/js/main.min.js': ['<%= concat.dist.dest %>']
}
}
},
jshint: {
files: ['development/js/**/*js'],
options: {
globals: {
jQuery: true,
console: true,
module: true
}
}
},
compass: {
dist: {
options: {
sassDir: 'development/css',
cssDir: 'dist/css',
environment: 'production',
outputStyle: 'compressed'
}
}
},
copy: {
files: [
{
cwd: 'development', // set working folder / root to copy
src: '**/*html', // copy all files and subfolders
dest: 'dist', // destination folder
expand: true // required when using cwd
},
{
cwd: 'development', // set working folder / root to copy
src: 'img/*', // copy all files and subfolders
dest: 'dist', // destination folder
expand: true // required when using cwd
},
{
cwd: 'development', // set working folder / root to copy
src: 'fonts/*', // copy all files and subfolders
dest: 'dist', // destination folder
expand: true // required when using cwd
},
{
cwd: 'path/to/files', // set working folder / root to copy
src: '**/*', // copy all files and subfolders
dest: 'dist', // destination folder
expand: true // required when using cwd
}
]
},
watch: {
files: ['<%= jshint.files %>', 'development/css/**/*.scss', 'development/**/*html'],
tasks: ['concat', 'uglify', 'jshint', 'compass']
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', [
'concat',
'uglify',
'jshint',
'compass',
'copy'
]);
};
控制台输出:
正在加载&#34; Gruntfile.js&#34;任务...错误
SyntaxError:意外的令牌(警告:任务&#34;默认&#34;未找到。使用--force继续。
因警告而中止。
答案 0 :(得分:3)
第一个函数有语法错误,尝试将第一个函数更改为:
(function(){
"use strict";
// Define your library strictly...
})();