简体   繁体   中英

Grunt: Custom Task - No “taskname” targets found

I recently created a custom task, doing the following

  1. Created an empty folder "custom-tasks" in Document Root
  2. Created the task file itself: "mytask.js"
  3. Implemented the functionality
  4. Registered the task to the "Gruntfile.js"

Unfortunately Grunt is giving me the error - "No "mytask" targets found", whenever I call the task.

This is the part of my Gruntfile.js --> init section:

my-task: {
  all: {
    options: {
      input_folder: 'input',
      output_file: 'result/result.xml'
    }
  }
},

Below I load the tasks:

grunt.loadTasks('./custom-tasks')

Then I register my-task:

grunt.registerTask('test', ['my-task']);

Can someone please help me, I'm new to Grunt and would like to have my custom task working. But all I get is the No-target-error.

Thank you!!!

I solved the issue by rebuilding the script from scratch. Got a 'typo', so the task wasnÄt able to be executed. Unfortunately grunt told that there were issues with the targets, what wasn't exactly the case.

Thanks anyway!

try something like this:

'use strict';

module.exports = function(grunt) {
    // Project Configuration
    grunt.initConfig({
       pkg: grunt.file.readJSON('package.json'),
    },
    my-task: {
    all: {
      options: {
        input_folder: 'input',
        output_file: 'result/result.xml'
      }
    }
});

require('load-grunt-tasks')(grunt);
// Making grunt default to force in order not to break the project.
grunt.option('force', true);
grunt.registerTask('test', ['my-task']);

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