gruntjs - 配置 grunt bower-install 时遇到问题

标签 gruntjs yeoman bower

我对 Yeoman 工作流程很陌生(今天开始使用 Yeoman)。
我正在尝试安装 grunt bower-install ,以实现 Assets 管理流程的自动化。

问题是,尽管我在尝试运行 grunt bower-install 时按照文档中的说明进行了最后操作。我收到错误。

尝试从主目录运行此命令时,错误如下:

oleg@ob:~$ !!
Running "bower-install:app" (bower-install) task
Verifying property bower-install.app.src exists in config...ERROR
>> Unable to process task.
Warning: Required config property "bower-install.app.src" missing. Use --force to continue.

Aborted due to warnings.


Execution Time (2014-01-20 10:17:47 UTC)
loading tasks      3ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 25%
bower-install:app  8ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 67%
Total 12ms

进入应用程序目录并再次运行命令后,我收到一个不同的错误:
oleg@ob:~/app$ grunt bower-install
Loading "gruntfile.js" tasks...ERROR
>> Error: Unable to read "package.json" file (Error code: ENOENT).
Warning: Task "bower-install" not found. Use --force to continue.

Aborted due to warnings.

任何帮助都非常感谢!

我的 Gruntfile.js(在 app/目录中)如下所示:
'use strict';

module.exports = function (grunt) {
    // Project configuration
    grunt.initConfig({
        // Metadata
        pkg: grunt.file.readJSON('package.json'),
        banner: '/*! <%= 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 <%= props.license %> */\n',
        // Task configuration
        concat: {
            options: {
                banner: '<%= banner %>',
                stripBanners: true
            },
            dist: {
                src: ['lib/<%= pkg.name %>.js'],
                dest: 'dist/<%= pkg.name %>.js'
            }
        },
        uglify: {
            options: {
                banner: '<%= banner %>'
            },
            dist: {
                src: '<%= concat.dist.dest %>',
                dest: 'dist/<%= pkg.name %>.min.js'
            }
        },
        'bower-install': {

          target: {
            // Point to the files that should be updated when
            // you run `grunt bower-install`
            src: ['/home/oleg/index.html'],

            // Optional:
            // ---------
            cwd: '',
            ignorePath: '',
            exclude: [],
            fileTypes: {}
          }
        },
        jshint: {
            options: {
                curly: true,
                eqeqeq: true,
                immed: true,
                latedef: true,
                newcap: true,
                noarg: true,
                sub: true,
                undef: true,
                unused: true,
                boss: true,
                eqnull: true,
                browser: true,
                globals: {
                    jQuery: true
                }
            },
            gruntfile: {
                src: 'gruntfile.js'
            },
            lib_test: {
                src: ['lib/**/*.js', 'test/**/*.js']
            }
        },
        qunit: {
            files: ['test/**/*.html']
        },
        watch: {
            gruntfile: {
                files: '<%= jshint.gruntfile.src %>',
                tasks: ['jshint:gruntfile']
            },
            lib_test: {
                files: '<%= jshint.lib_test.src %>',
                tasks: ['jshint:lib_test', 'qunit']
            }
        }
    });

    // These plugins provide necessary tasks
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-qunit');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-bower-install');

    // Default task
    grunt.registerTask('default', ['jshint', 'qunit', 'concat', 'uglify']);
};

最佳答案

你是对的grunt来自项目根目录的命令。但是,我相信您运行错误 grunt-bower-install子任务,从这个错误判断:

Running "bower-install:app" (bower-install) task
Verifying property bower-install.app.src exists in config...ERROR
>> Unable to process task.
Warning: Required config property "bower-install.app.src" missing.

如果你只是运行 grunt bower-install ,它应该工作。要么,要么重命名
'bower-install': {
    target: { /* ... */ }
}

到...
'bower-install': {
    app: { /* ... */ }
}

关于gruntjs - 配置 grunt bower-install 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21231383/

相关文章:

gruntjs - 保持点分隔文件 grunt-babel

angularjs - 最新的 Angular 生成器在我的 macbook pro 上抛出了很多错误

Bower 不兼容和解决问题

javascript - Bower 是否应该自动包含库 js 和 css 文件,这样它们就不需要列在 index.html 中

javascript - 使用 node-bourbon 设置 grunt-contrib-sass

javascript - Bower 指向错误的路径(jQuery-form-validator)

makefile - 什么是生成文件?它与 Gruntfile 或 npm run 有何不同?

node.js - Grunt 失败构建 "Arguments to path.join must be strings"错误

javascript - Yeoman 生成器命名

git - 如何使用私有(private) git 服务器 (SSH) 安装 bower 包?