目录

Managing Modules

As a basic functional unit of apps/atomic services, a module contains source code, resource files, third-party libraries, and configuration files. With Hvigor, you can easily manage multiple modules in a project, through the use of the build-profile.json5 configuration file or the hvigorconfig.ts script. hvigor also supports configuration, compilation, and packaging on a per-module basis.

Multi-Module Configuration

[h2]Statically Configuring Modules

In the project-level build-profile.json5 file, set the modules field to define modules in the project, including the module names, source code paths, and targets. For details about targets, see Configuring Multiple Targets and Products.

In the following example, the two modules in the project directory are added to the build-profile.json5 file to bind them to the project.

Project structure
└─ .hvigor directory    // Cache file directory of the build project, which does not need to be modified by developers and can be deleted.
└─ module1
   └─ Module source code file
   └─ build-profile.json5    // Module-level static build configuration file, which defines the build information of the current module and the build behavior of HAP (or HSP or HAR).
   └─ hvigorfile.ts    // Module-level custom dynamic build script file, which defines and extends the HAP (or HSP or HAR) build process.
   └─ Other configuration files
└─ module2
└─ hvigor directory
   └─ hvigor-config.json5    // Configuration file of the build engine, which defines the development-specific version number, dependent plug-in version, and Hvigor capability configuration.
└─ build-profile.json5    // Project-level static build configuration file, which defines the module information, app information, and app build behavior of the current project.
└─ hvigorfile.ts    // Project-level custom dynamic build script file, which defines and extends the app build process.
└─ Other configuration files

Other configuration files:

The following is an example of module configuration in the build-profile.json5 file:

{
  "modules": [
    {
      "name": "module1", // Module name. The name must be the same as the value of module.name in the module.json5 (or config.json in the FA model) file.
      "srcPath": "./module1" // Source code path of the module. It is the relative path of the module root directory relative to the project root directory.
    },
    {
      "name": "module2",
      "srcPath": "./module2"
    }
  ]
}

[h2]Dynamically Configuring Modules

You can dynamically add or exclude a module in the hvigorconfig.ts script. For details about APIs and examples, see HvigorConfig.

Module-specific Build

Hvigor allows you to build code on a per-module basis. To do so, use either of the following methods:

For more commands for building a HAR or an HSP, see Command Line Tools.