简体   繁体   English

咕unt声:自定义任务-未找到“任务名称”目标

[英]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 在文档根目录中创建一个空文件夹“ custom-tasks”
  2. Created the task file itself: "mytask.js" 创建任务文件本身:“ mytask.js”
  3. Implemented the functionality 实现功能
  4. Registered the task to the "Gruntfile.js" 将任务注册到“ Gruntfile.js”

Unfortunately Grunt is giving me the error - "No "mytask" targets found", whenever I call the task. 不幸的是,每当我调用任务时,Grunt都会给我错误-“未找到“ mytask”目标”。

This is the part of my Gruntfile.js --> init section: 这是我的Gruntfile.js-> init部分的一部分:

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. 有人可以帮我吗,我是Grunt的新手,希望我的自定义任务能够正常工作。 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. 不幸的是,咕unt的告诉他们目标存在问题,事实并非如此。

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']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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