Building Apps

Apps are built for production and deployments upon the Bit Component build pipeline. You can run the build pipeline to test your build by running the following command:

bit build my-app
CopiedCopy

After build is completed, you will get the output directory with the your build artifacts:

✔ Running build pipeline using 3 environment(s), total 28 tasks. Succeeded in 32s
build output can be found in path: ~/Bit/capsules/74ed1f4b911059ce5e8d4bc8bba6ce63e0568ced
CopiedCopy

You can now head to the directory to find and use your build artifacts.

Build upon release

Apps are built upon tag and their artifacts are persisted to the component version. To tag or snap your components run one the following commands:

bit tag -v 1.0.0 --message "releasing new header"
CopiedCopy

Alternatively, you can use snap to release for testing or development purposes:

bit snap --message "added a new header logo"
CopiedCopy

Using artifacts

After your release components using snap or tag you can use the following command to obtain and your build artrifacts:

bit artifacts my-app --out-dir app-bundle
CopiedCopy

The above command, will write your component artifacts to the app-bundle directory in your project.

Add a build task

You can add your tasks to the app build by implementing a build function. To do that create a build function and use it in your .bit-app.ts file.

import type { AppBuildContext } from '@teambit/application';
import { build } from 'esbuild';

export function build(context: AppBuildContext) {
  const rootPath = context.capsule.path;
  const outputDir = join(rootPath, 'build');

  const result = await build({
    entryPoints: [rootPath],
    bundle: true,
    platform: 'node',
    outfile: outputDir,
  });

  return {
    errors: result.errors.map((error) => {
      return new Error(error.detail);
    }),
    artifacts: [
      {
        name: 'my-artifact',
        globPatterns: [outputDir],
      },
    ],
  };
}
CopiedCopy

The example above builds a Bit Component for a node platform target using esbuild and returns the artifact to be persisted in your Bit Component.