Using build tasks

Build tasks are not coupled to a specific env or an aspect. This means you can create your own build task as a component and use it where-ever it makes sense for you.
These steps show how to use an independent build task in either an env or an aspect.

Use build task in an env

If you have a custom env, you can include a build task (BuilderEnv) in your Env's class (located in your Env's *.env.ts file).
Use the appropriate Builder service handler to provide the Builder service with an array of build tasks to run.

  • getBuildPipe: To add a task to the Build Pipeline
  • getTagPipe: To add a task to the Tag Pipeline
  • getSnapPipe: To add a task to the Snap pipeline
import { BuilderEnv } from '@teambit/envs';
import { MyBuildTask } from '@my-org/';
import { MyEnvAspect } from './my-env.aspect';

// The Env class should only implement the services it overrides
export class MyEnv implements BuilderEnv {
  getBuildPipe() {
    return [new MyBuildTask(];

Pass the base Env instance through the constructor and use its getBuildPipe method to retrieve its build tasks array.

import { ReactEnv } from '@teambit/react';
// ...

export class ReactLocStats implements BuilderEnv {
  constructor(private reactEnv: ReactEnv) {}

  getBuildPipe() {
    return [...this.reactEnv.getBuildPipe(), new MyBuildTask(];
Create a custom env

To create a custom env, follow these steps.

Register a Build Task via an Aspect

If you are building an aspect, you may also register build tasks.
Create a new aspect:

bit create aspect aspects/my-aspect -s my-scope

To use the Builder API, import its 'Aspect' module and set it as a dependency of your Aspect (this will be used by Bit to inject an instance of builder upon execution).

Use the appropriate API to register the task to the right build pipeline:

  • registerBuildTasks(tasks: BuildTask[]): To add a task to the Build Pipeline
  • registerTagTasks(tasks: BuildTask[]): To add a task to the Tag Pipeline
  • registerSnapTasks(tasks: BuildTask[]): To add a task to the Snap pipeline
import { MainRuntime } from '@teambit/cli';
import { BuilderMain, BuilderAspect } from '@teambit/builder';
import { MyBuildTask } from '@my-org/';
import { MyAspectAspect } from './my-aspect.aspect';

export class MyAspectMain {
  static dependencies = [BuilderAspect];
  static runtime = MainRuntime;
  static async provider([builder]: [BuilderMain]) {
    builder.registerBuildTasks([new MyBuildTask(]);
    return new MyAspectMain();


To use the build task, set the Aspect that registers it in the workspace config or component config:

  "": {}