Continuous Deployment with npm
Setting up CircleCI to publish packages to the npm registry makes it easy for project collaborators to release new package versions in a consistent and predictable way.
Obtain the npm authToken for the account that you wish to use to publish the package.
You can do that by logging in to npm (
npm login). This will save the authToken to the
~/.npmrcfile. Look for the following line:
In this case, the authToken is
Go to your project settings, and set the
NPM_TOKENvariable to the obtained authToken.
Configure CircleCI to add the authToken to
dependencies: pre: - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
Configure CircleCI to run
npm publishon tagged commits:
deployment: npm: tag: /v[0-9]+(\.[0-9]+)*/ commands: - npm publish
When you want to publish a new version to npm, run
npm versionto create a new version:
npm version 10.0.1
This will update the
package.jsonfile and creates a tagged Git commit. Next, push the commit with tags:
git push --follow-tags
If tests passed, CircleCI will publish the package to npm automatically.