bit icon indicating copy to clipboard operation
bit copied to clipboard

Confusion over build() function

Open kamontat opened this issue 1 year ago • 2 comments

Description

What is the difference between build() function on bit-app and bit-env?

Specifications

  • Bit version: latest
  • Node version: 18
  • npm / yarn version: 8.14.1
  • Platform: macos
  • Bit compiler (include version):
  • Bit tester (include version):

Context and additional information

kamontat avatar Feb 11 '24 15:02 kamontat

Great question - it's probably based on a slight confusion about what a bit-app is, so i'll try to quickly clear up.

A bit-app component is just another standalone component, shareable and must itself have an env which will compile it, test it, package it. It's not an env, which is essentially just a component for managing other components.

But while all other components are deployed by creating a version of them that will be consumed in an eventual application, an app component needs to be fully production ready and served to a CDN. So in addition to the regular build tasks an env runs on components (compilation, testing, creating examples and docs, packaging etc), an app component needs some extra build actions applied to it - in the main, creating the production bundle.

So the build() function of an env contains tasks involved in the creation of a deployable version of the component (plus some bit features such as docs, component previews, etc), while on top of the env's build, the app component's build() handles the extra production bundling that the application requires in order to be deployed.

So they're named the same as they actually get invoked during the same build pipeline, but they each have their own responsibilities

benjgil avatar Feb 11 '24 18:02 benjgil

@benjgil When will bit-app build() run? I try to run bit build --include-tag but only bit-env build() was run (indicated by no log produce when run)

kamontat avatar Feb 12 '24 02:02 kamontat

Hi, you can find information on running a build function for an app or through an env here - https://bit.dev/reference/build-pipeline/implement-build-task

in general, when in App, the build task is specific for the component, and when through an env, the build task will run for all components configured with that env.

both will run during the bit build command (and as such, as part of bit tag or snap).

you can always run this command to see all tasks for a component:

bit build --list-tasks <component-id>

itaymendel avatar Feb 26 '24 10:02 itaymendel

I had the same issue as @kamontat and couldnt get the app to run its build or deploy script if I ran bit build it only seems to run with bit tag -b or bit snap -b

sbland avatar May 06 '24 20:05 sbland