[英]Bit.dev unable to add 2 components with the same ID
To manage my severals react
components I decide to use bit .为了管理我的几个
react
组件,我决定使用bit 。 Then I add a component loginForm
that is a directory with this structure:然后我添加一个组件
loginForm
,它是一个具有以下结构的目录:
├── loginForm
│ ├── loginForm.scss
│ └── loginForm.tsx
I use for that the cli command add
:我使用 cli 命令
add
:
bit add ./loginForm/*
But I get this error that I don't really understand:但是我得到了这个我不太明白的错误:
unable to add 2 components with the same ID: login-form/login-form
无法添加 2 个具有相同 ID 的组件:login-form/login-form
As someone an idea ?作为一个想法?
the only possible solution for me looks like to change one filename eg对我来说唯一可能的解决方案看起来像更改一个文件名,例如
├─loginForm
│ │ loginForm.tsx
│ │ loginForm.style.scss
Bit uses glob patterns to "find" files and create a set distinct add
command, each to a set of files. Bit 使用 glob 模式来“查找”文件并创建一组不同的
add
命令,每个命令都指向一组文件。 So in this case, the use of a wildcard ( *
) in a folder with two files, returned 2 files to the bit add
command to iterate over.所以在这种情况下,在包含两个文件的文件夹中使用通配符 (
*
),将 2 个文件返回给bit add
命令进行迭代。
ie the syntax in the question is a "snippet" to run:即问题中的语法是要运行的“片段”:
$ bit add loginForm/loginForm.tsx
$ bit add loginForm/loginForm.scss
With these two commands, Bit's default behavior is taking the file name to be tracked, and use it as the component name.使用这两个命令,Bit 的默认行为是获取要跟踪的文件名,并将其用作组件名称。 So both cases it's
login-form
.所以这两种情况都是
login-form
。 Bit does not allow having two components with identical IDs. Bit 不允许具有相同 ID 的两个组件。
To have Bit track the entire folder as a component you can omit the wildcard and run:要将 Bit 作为组件跟踪整个文件夹,您可以省略通配符并运行:
$ bit add ./loginForm
This way you tell Bit to track the entire directory as a single component, not tracking each individual file as a component.通过这种方式,您告诉 Bit 将整个目录作为单个组件进行跟踪,而不是将每个单独的文件作为一个组件进行跟踪。
It's also possible to group the results of a glob pattern to a single component using the --id
option.也可以使用
--id
选项将 glob 模式的结果分组到单个组件。 This tells Bit to take all files found in the glob pattern and instead of running "many" bit add
(for each file/directory), it runs a single one with a set component ID.这告诉 Bit 获取在 glob 模式中找到的所有文件,而不是运行“许多”
bit add
(对于每个文件/目录),它运行具有设置组件 ID 的单个文件。 For example:例如:
$ bit add ./loginForm/* --id login-forum
This way it tells Bit to add all files in the ./loginForm
directory to be tracked by a single component instance.通过这种方式,它告诉 Bit 添加
./loginForm
目录中的所有文件以供单个组件实例跟踪。 Using the --id
option you can also add files to that component even after it was tracked, as it tells Bit to add
files to the mentioned component ID.使用
--id
选项,您还可以将文件添加到该组件,即使它被跟踪,因为它告诉 Bit add
文件add
到提到的组件 ID。
If you have several folders containing files and you want each folder to be a component and use a single command, then you can use the glob pattern.如果您有多个包含文件的文件夹,并且您希望每个文件夹成为一个组件并使用单个命令,那么您可以使用 glob 模式。
├── LoginForm
│ ├── LoginForm.scss
│ └── LoginForm.tsx
└── LogoutForm
├── LogoutForm.scss
└── LogoutForm.tsx
You could run:你可以运行:
$ bit add ./*
To have the glob pattern give bit add
the two folders to track.要让 glob 模式给
bit add
两个要跟踪的文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.