Changing scopes

Bit Components are owned and managed in scopes. Every component has a scope assigned to it, which becomes part of the component's ID, and is where your component will be exported to and imported from.

Head over to bit.cloud's 'create-scope' page to create a scope to host your components. Alternatively, create a scope on a self-hosted server.

Set the workspace default scope

The defaultScope for components in a workspace can be set either when creating the workspace by adding the --default-scope flag to the bit new command, or set/updated manually in an existing workspace.

Run the following to set the default scope in an existing workspace:

$bit
Copiedcopy

Your workspace.jsonc file should be updated accordingly:

{
  "teambit.workspace/workspace": {
    "defaultScope": "my-account.my-scope"
  }
}
CopiedCopy

Components created in this workspace will be set with the my-account.my-scope scope by default.

Create a component with a non-default scope

Use the --scope flag to override the default scope when creating a component:

$bit
Copiedcopy
See command synopsis

Change a component's scope

Run the following to change a component's scope:

$bit
Copiedcopy

To change the scope of multiple components, use a glob pattern that matches the components you wish to change:

$bit
Copiedcopy
note

A component's scope is part of its ID and can only be changed while it is still new, i.e. unversioned. Once a component is versioned, see renaming components for changing its scope.

Rename the scope of multiple components in workspace

You can replace a scope with another, for all new, unversioned components in your workspace assigned that specific scope, with the bit scope rename command:

$bit
Copiedcopy

This command will change the scope of all new, unversioned workspace components currently on the my-current-account.my-current-scope scope to my-new-account.my-new-scope.

The --refactor flag updates import statements in components that use the old package names (based on the old scope name) to the new package name.