首页 文章

加载“gruntfile.js”任务...错误>> SyntaxError:意外的标识符警告:找不到任务“默认” . 使用--force继续

提问于
浏览
1

这是我的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”任务...错误>> SyntaxError:意外的标识符警告:找不到任务“default” . 使用--force继续 .

当我注释掉SASS块(在gruntfile.js中)...然后grunt说:运行“观察”任务等待......一切正常!

有谁知道什么可能是一个问题?

2 回答

  • 0

    对我来说,似乎有一些简单的拼写错误,缺少 , 等等 . 另外,尝试注册这样的任务:

    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
    
  • 3

    我的理由是我下载了zip文件,而zip文件不包含源文件,只包含构建的文件,因此不需要grunt任务 . 我使用 git clone 来克隆源文件,解决了这个问题 .

相关问题