NPM publishing - noi-techpark/odh-web-components GitHub Wiki

Publish package to NPM


To make your package easily accessible and understandable, you need to document it well. To do that create a file on the root of your repository and create a nice looking guide to your package. This will be than be displayed as the first page of your package on the official npm repo. This might already decide if your package gets used or not so do it well.

Think before you hit publish

  • Once published you will never again be able to publish the specified package with that version you just used (not even if you unpublish it)
  • Unpublishing a release version is only permitted withing first 3 days after release

Publishing first release

To publish the code you need to setup you local NPM with your npm account.

npm login //you only need to do this once

Next you will need to publish the package with a public scope.If you're starting from scratch initialize your package with npm init ...

cd <webomponent-folder>`
npm init [email protected]<my-org>

... or else change the package.json with the name containing the scope e.g.

"name": "@<my-org>/<webomponent-name>"

To avoid publishing everything from your webcomponent folder, create a .npmignore file in the root of your repository and exclude content with the same syntax as you do with .gitignore( If you do not specify a .npmignore npm will automatically fall back on .gitignore.

Once you feel ready and you think the time has come for your first official release type:

npm publish --access public

Publish further releases

NPM expects semantic versioning and therefore has some easy to use utility. Just type:

npm version <type>

where type is one of patch, major, or minor. package.json will be automatically updated and you just do npm publish --access public again to create a new release.

Main sources:

⚠️ ** Fallback** ⚠️