Use verdaccio as npm registry
Sometimes you want to test a not published package inside other project.
The normal solutions are npm link
(or yarn link
) and yarn workspaces.
Sometimes, this standard soulutions doesn't fit.
For example, npm link
expects both projects to use the same node version.
In those cases, you can setup your own private npm server with verdaccio.
1. Start server #
I prefer docker to manage it. Here's a one-liner to start the server:
docker run -it --rm --name verdaccio -p 4873:4873 verdaccio/verdaccio
2. Publish the component #
First, you must login into the registry:
npm login --registry http://localhost:4873
If the component name is prefixed (like @danigb/my-component
, for example) use that prefix as username. For example:
> npm login --registry http://localhost:4873
Username: danigb
Password: ********
Email: (this IS public) danigb@gmail.com
Logged in as danigb on http://localhost:4873/.
Finally, publish the component:
npm publish --registry http://localhost:4873
3. Install the component #
In the target project run:
npm install @user/component-name --registry http://localhost:4873
Bonus: scripts #
As you probably now, I like to write all things things inside a package.json scripts to document:
package.json
:
{
"scripts": {
"registry:start": "docker run -it --rm --name verdaccio -p 4873:4873 verdaccio/verdaccio",
"registry:login": "npm login --registry http://localhost:4873",
"registry:install": "npm install @user/component-name --registry http://localhost:4873",
"registry:publish": "npm publish --registry http://localhost:4873"
}
}
🖖