【问题标题】:Loading "gruntfile.js" tasks...ERROR >> SyntaxError: Unexpected identifier Warning: Task "default" not found. Use --force to continue正在加载“gruntfile.js”任务...错误>> SyntaxError:意外标识符警告:找不到任务“默认”。使用 --force 继续
【发布时间】:2015-04-05 06:55:36
【问题描述】:

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

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

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

【问题讨论】:

    标签: gruntjs grunt-contrib-watch


    【解决方案1】:

    对我来说,似乎只是一些简单的错字,缺少, 等 另外,尝试注册一个这样的任务:

    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
    

    【讨论】:

    • 非常感谢,您的建议有所帮助...... grunt 正在运行“Watch”任务并等待......但是当我在 styles.scss 中更改某些内容并保存时,我得到了这个:运行“watch " 任务等待... >> 文件 "_\components\sass\styles.scss" 已更改。警告:找不到任务“compass:dev”。使用 --force 继续。由于警告而中止。 2015 年 2 月 5 日星期四 14:27:39 GMT+0100(西欧标准时间)在 1.753 秒内完成 - 等待中...
    • 太好了,如果答案有助于回答您的问题,您可以单击大勾号接受它,以便其他人知道哪种解决方案有效。如果仍有问题,请提供详细信息,谢谢
    • 你在watch任务中调用['compass:dev'],但是你还没有加载compass插件。您需要安装并加载“指南针”插件:grunt.loadNpmTasks('grunt-contrib-compass'); 或您正在使用的任何指南针插件
    • 这解决了问题...一切正常!!!再次感谢您的帮助。我通过单击大勾号接受了您的回答! :)(对不起,我一开始没有这样做,我是新来的)
    • 很高兴它起作用了,当我第一次开始时,我也不知道勾号和赞成票是如何起作用的,所以我想我会提到它。
    【解决方案2】:

    我的原因是我下载了 zip 文件,而且 zip 文件不包含源文件,只有构建文件,所以不需要 grunt 任务。我使用git clone克隆源文件,解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2019-11-29
      • 1970-01-01
      • 1970-01-01
      • 2014-01-30
      • 2016-08-27
      相关资源
      最近更新 更多