Mohan pd.
Mohan pd. Author of The Coders Blog. Also a professional fullstack javascript developer working with various tech company and client around world.

Using yarn and npm for publishing npm packages.

Aug 04, 2019 · 1 min
Using yarn and npm for publishing npm packages.

Setting up the pre-release version for npm package.

If you already have a package in NPM registry and need a per-release to test minor or major updates among fellow tester then npm has next tag to achieve this. Here are those simple steps:

  • Update package.json file to set a pre-release version. With yarn you can run yarn version to update version info in package.json file. Pre-release version e.g: 2.0.0-rc1, 3.1.5-rc4
  • Run npm publish yourpackage.tgz --tag next to publish the package under the next tag. For yarn: yarn publish yourpackage.tgz --tag next
  • Run npm install --save [email protected] to install prerelease package

Unpublish specific version for NPM registry

To remove specific version from npm registry use following command:
npm unpublish [email protected]
yarn unpublish [email protected]

Adding JSDelivr.

To add JSDelivr to distribute package from CDN add following lines in package.json:
"unpkg": "dist/index.js",
"jsdelivr": "dist/index.js"

Also, it is important to update index.js file location.

Use Library to automate publishing task.

A package call np can automate a lot of publishing task & has other helpful feature.

Here are simple steps: npm install --global np to install it globally.
Run np on project directory. It will show interactive UI steps to perform publish.

comments powered by Disqus