简体   繁体   中英

grunt bowercopy task not found

I can't figure out my configuration problem. When I try to run 'grunt bowercopy', I get this error message:

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

If I run 'grunt jshint', jshint works fine.

Here is my package.json:

{
     "name": "treblebull",
      "version": "0.0.1",
      "private": true,
      "dependencies": {
        "express": "~3.2.6",
        "jade": "~0.31.2",
        "underscore": "~1.5.2",
        "pg": "~2.11.1"
      },  
      "devDependencies": {
        "grunt": "~0.4.2",
        "grunt-bowercopy": "~0.7.1",
        "grunt-contrib-jshint": "~0.8.0",
        "load-grunt-tasks": "~0.2.1"
      }
    }

and here is my gruntfile:

    'use strict';

    module.exports = function(grunt) {

      grunt.initConfig({
        jshint: {
          options: {
            jshintrc: '.jshintrc'
          },  
          gruntfile: {
            src: 'Gruntfile.js'
          },  
          lib: {
            src: ['lib/**/*.js']
          },  
          test: {
            src: ['test/**/*.js']
          }   
        },  
        bowercopy: {
          options: {
            clean: true
            //srcPrefix: 'bower_components'
          },  
          libs: {
            options: {
             // destPrefix: 'public/js/lib'
            },  
            files: {
              'angular.js': 'angular/angular.js'
              //'underscore.js': 'underscore/underscore.js',
              //'underscore.string.js': 'underscore.string/underscore.string.js'
            }   
          }   
        }   
      }); 

      grunt.loadNpmTasks('grunt-bowercopy');
      grunt.loadNpmTasks('grunt-contrib-jshint');

    };

Run bower init to give yourself a bower.json file for the bowercopy task to read. Also if you already have installed everything via bower, set runBower to false in your options hash.

If you're ever having Grunt failures, it's worth running with the --v (verbose) flag to see exactly what it's failing on. Running this myself I saw it looking for a bower.json , and once I supplied one the task succeeded.

You're missing task registration, You need to register a task that you want to explicity run in grunt, so you need this

grunt.registerTask('bowercopy', ['bowercopy']);

Then you can run

grunt bowercopy

Since I can't comment on @dcodesmith's answer due to points, I have to leave an answer. I ran into the problem in that actually adding grunt.registerTask('bowercopy', ['bowercopy']); called bowercopy's task, but it doesn't actually work. Removing it actually allowed bowercopy to copy files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM