这是我的gruntfile.js
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.initConfig({
uglify:{
my_target: {
files:{
'_/js/script.js': ['_/components/js/*.js']
}//files
}//myTarget
},//uglify
compass: {
dev:{
options: {
config: 'config.rb',
}//options
}//dev
},//compass
watch: {
options: {livereload: true},
scripts: {
files: ['_/components/js/*.js'],
tasks: ['uglify']
},//scripts
html: {
files: ['*.html']
},//html
sass: {
files: ['_/components/sass/*.scss']
tasks: ['compass:dev']
},//sass
}//watch
})//initConfig
grunt.registerTask('default','watch');
}//exports
在命令提示符下运行grunt会出现错误:正在加载"gruntfile.js"任务。。。错误>>语法错误:意外的标识符警告:找不到任务"默认"。使用--force继续。
当我评论掉SASS块(在gruntfile.js中)…然后grunt说:正在运行"监视"任务等待。。。一切都很好!
有人知道什么可能是问题吗?
对我来说,似乎只是有几个简单的打字错误,缺少,
等此外,尝试注册这样的任务:
grunt.registerTask('default', ['watch']);
这是一个整理的版本,希望这对你有用。
module.exports = function(grunt) {
grunt.initConfig({
uglify: {
my_target: {
files: {
'_/js/script.js': ['_/components/js/*.js']
} //files
} //myTarget
}, //uglify
compass: {
dev: {
options: {
config: 'config.rb'
} //options
} //dev
}, //compass
watch: {
options: {
livereload: true
},
scripts: {
files: ['_/components/js/*.js'],
tasks: ['uglify']
}, //scripts
html: {
files: ['*.html']
}, //html
sass: {
files: ['_/components/sass/*.scss'],
tasks: ['compass:dev']
} //sass
} //watch
});
//initConfig
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['watch']);
} //exports
我的原因是我下载了zip文件,并且zip文件不包含源文件,只包含构建的文件,所以不需要繁重的任务。我使用git clone
来克隆源文件,解决了这个问题。