目录

Developing an Hvigor Task

Understanding a Task

As a basic execution unit in the Hvigor build process, a task usually contains a segment of executable code, and it can depend on multiple other tasks. During task scheduling, Hvigor parses dependencies to determine the task execution sequence.

UP-TO-DATE

This task ID indicates that the task is not actually executed. Hvigor supports the incremental task skipping mechanism. If the input and output conditions of a task do not change during secondary task execution, the task is skipped to improve the build efficiency.

Example:

> hvigor UP-TO-DATE ::PackageApp...

Finished

This task ID indicates that the task is finished.

Example:

> hvigor Finished ::PackageApp... after 310 ms

Registering a Task

A task is registered using the HvigorNode object.

  1. Modify the hvigorfile.ts file in the project.

    // Import the module.
    import { getNode, HvigorNode, HvigorTask } from '@ohos/hvigor';

  2. Build service code.

    // Obtain the current hvigorNode object.
    const node: HvigorNode = getNode(__filename);
    
    // Register the task.
    node.registerTask({
      name: 'customTask',
      run() {
        console.log('this is Task');
      }
    });

  3. Execute the task.

    Execute the task using the Hvigor command line tool.

    hvigorw customTask

  4. View the task execution result.