Skip to content

Instantly share code, notes, and snippets.

@ronny
Last active April 13, 2020 07:59
Show Gist options
  • Save ronny/64a6f2f304eb72633939 to your computer and use it in GitHub Desktop.
Save ronny/64a6f2f304eb72633939 to your computer and use it in GitHub Desktop.
Publishing an NPM package

Building

Stolen from rackt/redux.

Relevant package.json snippet:

  "build:lib": "babel src --out-dir lib",
  "build:umd": "webpack src/index.js dist/my-pkg-name.js --config webpack.config.development.js",
  "build:umd:min": "webpack src/index.js dist/my-pkg-name.min.js --config webpack.config.production.js",
  "build": "npm run build:lib && npm run build:umd && npm run build:umd:min",

You shouldn't need to build manually for publishing. Use the npm lifecycle hooks below to automate it.

Bump Version

npm version patch -m "Summary of this version"

Relevant npm lifecycle scripts in package.json, e.g:

  "preversion": "npm run clean && npm run lint",
  "version": "npm run build",
  "postversion": "git push && git push --tags && npm run clean",

Publishing

Ensure logged in:

npm adduser
npm login

Check owners of a package:

npm owner ls

Add another user as an owner (so they can publish):

npm owner add ...

To actually publish the current directory (after doing npm version first):

npm publish

To check what would be published, check with npm pack to generate a tarball:

npm pack

If things are being excluded, check for the presence of .npmignore, if it's missing, then npm will use the default which will exclude many things. So, either override with an empty .npmignore file to incluce everything, or tweak to your liking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment