【问题标题】:Grunt does not find the lint taskGrunt 没有找到 lint 任务
【发布时间】:2014-06-10 00:07:31
【问题描述】:

我继承了一个由 Grunt 管理的项目(实际上是一个旧版本,我不确定是哪个),而且我完全是新手。

通过阅读文档,我做了两个看起来合乎逻辑的更改(我想符合最新规范):将由空格分隔的单个字符串中的任务列表转换为正确的列表。

module.exports = function(grunt) {

    // Project configuration.
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        meta: {
            banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
                '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
                '<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
                '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
                ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
        },
        handlebars: {
            all: {
                src: 'src/templates/',
                dest: 'dist/templates.js'
            }
        },
        require : {
            all: {
                src : 'src/scripts/app.build.js',
                dest: 'dist/<%= pkg.name %>.js'
            }
        },
        concat: {
            dist: {
                src: ['<file_strip_banner:src/scripts/bootstrap.js>', '<file_strip_banner:dist/<%= pkg.name %>.js>'],
                dest: 'dist/<%= pkg.name %>.js'
            }
        },
        min: {
            dist: {
                src: ['<config:concat.dist.dest>'],
                dest: 'dist/<%= pkg.name %>.min.js'
            }
        },
        qunit: {
            files: [
                'test/**/*.html',
                'test/**/*.js'
            ]
        },
        lint : {
            browser : [
                'grunt.js',
                'src/scripts/*.js',
                'src/scripts/storage/**/*.js',
                'src/scripts/util/*.js',
                'test/**/*.js',
                'src/templates/helpers/*.js'
            ],
            node : [
                'build/**/*.js',
                'tasks/**/*.js'
            ]
        },
        watch: {
            files: [
                // '<config:handlebars.src>',
                '<config:lint.browser>',
                '<config:qunit.files>'
                ],
            tasks: ['lint', 'handlebars', 'require']
        },
        jshint : {
            browser : {
                options : {
                    curly: true,
                    eqeqeq: true,
                    immed: true,
                    latedef: true,
                    newcap: true,
                    noarg: true,
                    sub: true,
                    undef: true,
                    boss: true,
                    eqnull: true,
                    browser: true
                },
                globals : {
                    JQuery: false,
                    Handlebars: false,
                    templates: false
                }
            },
            node : {
                options : {
                    esnext : true,
                    strict : false
                },
                globals : {
                    module : true,
                    require : true,
                    setTimeout : true,
                    Buffer : true,
                    process : true
                }
            }
        },
        uglify: {
            'overwrite': true,
            'unsafe': true,
            'lift-vars': true
        }
    });

    grunt.loadTasks('tasks');

    // Default task.
    grunt.registerTask('default', ['lint', 'handlebars', 'require', 'concat', 'min']);

};

当我运行 grunt 时,我得到的消息是:

Warning: Task "lint" not found. Use --force to continue.

Aborted due to warnings.

显然在配置中定义了一个lint 任务。

有什么想法可能会失败吗?

【问题讨论】:

  • 传递给grunt.initConfig() 的 lint 对象没有定义 lint 任务,它只是为 lint 任务提供配置。 grunt.loadTasks('tasks'); 将加载您的本地任务。 '/tasks' 目录中是否有 lint.js 任务?
  • 既然你说...只有handlebarsTask.jsrequireTask.js
  • 您似乎继承了一个损坏的 grunt 构建系统。本质上,任务缺失。您可以定义“本地”任务(示例是您列出的任务),也可以将 npm 模块加载为 grunt 任务。在您继承此代码之前,这个 grunt 设置是否有效?
  • 我想是的,我团队的其他成员使用了它(尽管他不是一开始创建它的人)
  • 有道理!以下是可用于替换旧默认任务的 npm 任务列表:github.com/gruntjs/grunt/wiki/…

标签: gruntjs


【解决方案1】:

旧版本的 Grunt (v0.3) 包含一组默认任务。从 Grunt 0.4 开始,Grunt 0.3 中包含的八个核心任务现在是单独的 Grunt 插件。

因此需要定义lintconcatmin 任务。您可以使用grunt.loadNpmTasks 加载这些任务

以下是可用于替换默认任务的插件列表:http://gruntjs.com/upgrading-from-0.3-to-0.4#core-tasks-are-now-grunt-plugins

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多