Skip to main content

Initializing a Workspace

In order to initialize a workspace you will need to first install Bit. A Bit Workspace enables you to author and manage multiple independent components in a simple and elegant way. Bit works with Git so you can either add init a new git repo or add Bit to an existing git repo.

Quick Guide#

For those that don't like reading docs feel free to follow the quick guide at the top of each page.

  1. Start a new bit project
bit new react <my-workspace-name>
  1. Open the directory that has just been created and run bit start
cd <my-workspace-name>bit install

There are two ways you can initialize a workspace:

Option 1: Use bit new to create a React workspace#

Create a new Bit workspace for a React environment. This command will initialize a Bit Harmony workspace configured for a React environment complete with demo components and a custom env.

bit new react <my-workspace-name>
cd <my-workspace-name>bit install
tip

Use bit new --help or bit new -h to get a list of available options for this command.

Option 2: Use bit init to initialize and manually configure your workspace#

Initialize a Bit Harmony workspace and then manually configure the environment and install any peer dependencies needed.

bit init --harmony

Once installed you should get the following message:

successfully initialized a bit workspace.
tip

Use bit init --help or bit init -h to get a list of available options for this command.

Setting a React Environment#

Uncomment the following line in your workspace.jsonc file, to apply the React development environment on all components in this workspace.

workspace.jsonc
"teambit.workspace/variants": {  "*": {    "teambit.react/react": { }  }}

Install React and React Dom as peer dependencies:

bit install react --type peerbit install react-dom --type peer

Created Files#

Bit creates the following files when initializing a new workspace:

  • workspace.jsonc - The workspace configuration file that sets rules and policies for the workspace and all its components.
  • .bitmap - An auto-generated mapping between tracked components in the workspace and their physical location on the file system. The file-structure of your workspace is entirely up to you.
  • .git/bit (hidden directory) - Your local scope. Where your workspace's component release versions are stored.

Committing to git#

Both the workspace.jsonc and the .bitmap should be commited to git. The .git/bit folder will be automatically ignored by git.


What's Next#

Once you have initialized a workspace, you can start creating components.