How to self host components and publish to npm #4707
-
Hosting components is easily done with Bit.dev however you can also self host your components and publish them to a public registry such as npm. How can this be done? |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 12 replies
-
Self-Hosted a ScopeThe easiest way to export your components is to host them on the Bit Cloud. However if you prefer to host them yourself you can do so by creating your own server. Creating your own ServerTo create your own remote server you can run the mkdir my-server
cd my-server
bit init --bare Start your ServerTo start your server you can run the bit start This will open up the server on the available port eg. Update your Default ScopeIn the {
"defaultScope": "my-server"
} If you have already created some components you will need to modify the import statements in your components to point to the new default Scope. Once you do that run Add your Remote ScopeIn the workspace where you want to export your components run the bit remote add http://localhost:3001 # url of the scope Publish your Components to NPMAlthough we recommend using Bit Cloud to host your components you can publish your components to the npm registry if you prefer. Bit will create and manage a The "teambit.workspace/variants": {
"{ui/**}": {
"teambit.react/react": {},
"teambit.pkg/pkg": {}
}
} Make your Components PublicIf you want to make your package a public package on npm add "teambit.workspace/variants": {
"{ui/**}": {
"teambit.react/react": {},
"teambit.pkg/pkg": {
"packageManagerPublishArgs": [
"--access public"
],
}
}
} Override the Package.jsonWe can override the properties of the "teambit.workspace/variants": {
"{ui/**}": {
"teambit.react/react": {},
"teambit.pkg/pkg": {
"packageManagerPublishArgs": [
"--access public"
],
"packageJson": {
"name": "@{scope}/{name}",
"private": false
}
}
}
} You can add other key/value pairs to the Setting the Scope and registryIn order to publish our components to the npm registry we first must login to npm and add a new organization/scope in npm. We can then add the name of this organization/scope to the "teambit.workspace/variants": {
"{ui/**}": {
"teambit.react/react": {},
"teambit.pkg/pkg": {
"packageManagerPublishArgs": [
"--access public"
],
"packageJson": {
"name": "@{scope}/{name}",
"private": false,
"publishConfig": {
"scope": "@test-remote",
"registry": "https://registry.npmjs.org/"
}
}
}
}
} Here we are publishing to npmjs.org, but it's also possible to publish to Artifactory, Nexus or Verddacio. Logging in to npmIn the terminal login to npm so that you can use Bit to publish your components to npm. npm login Tagging your ComponentsIn order to publish components they must be tagged by using the bit tag --all Exporting your ComponentsAfter tagging is complete components can be exported to your remote scope on your self hosted server using the bit export Use your ComponentsYour components are now visible on npm as well as on your remote scope and can now be installed to any project or application using the package manager of your choice. npm install @scope/component-name
yarn add @scope/component-name You can add a README.md file to your component's directories to provide more information about your component. |
Beta Was this translation helpful? Give feedback.
-
If you want to host your remote scope using docker you can find info on how to do that here: |
Beta Was this translation helpful? Give feedback.
-
Can we change public registry to private registry with NPM token to publish ? |
Beta Was this translation helpful? Give feedback.
-
I am getting below error on running the
I tried running |
Beta Was this translation helpful? Give feedback.
-
Changing the name in the below: "packageJson": {
"name": "@{scope}/{name}",
"private": false
} Causes the following error when running
|
Beta Was this translation helpful? Give feedback.
-
I have tried to follow the above instructions, but when I try to run bit start, I get this error:
I have tried to install the package '@pmmmwh/react-refresh-webpack-plugin' and I still get the same error. Any ideas?? |
Beta Was this translation helpful? Give feedback.
-
I have deployed the server according to the above method,and self host components and publish to private npm。However, every body uses "bit tag" tag the components, needs to login npm,it is very complex。I want to apply to a common accout to for team member to use "bit tag",how I should do ? thanks~~ |
Beta Was this translation helpful? Give feedback.
-
Recently my |
Beta Was this translation helpful? Give feedback.
-
Hi team. Is there a way I can publish the bit components in gitlab package registry as private packages? if yes, how? |
Beta Was this translation helpful? Give feedback.
Self-Hosted a Scope
The easiest way to export your components is to host them on the Bit Cloud. However if you prefer to host them yourself you can do so by creating your own server.
Creating your own Server
To create your own remote server you can run the
bit init --bare
command. This will create a bare version of Bit.dev that you can use to host your own components.mkdir my-server cd my-server bit init --bare
Start your Server
To start your server you can run the
bit start
command.This will open up the server on the available port eg.
http://localhost:3001
. You will notice that it is an empty remote scope as no components have been exported yet.Update your Default Scope
In …