Publish npm packages using npm publish

Trevor Miller
InstructorTrevor Miller

Share this video with your friends

Send Tweet

In this lesson we will publish our package. We will first add a prepublish script that runs our build script; this will ensure the built folder gets added to npm when published. We will also add a .npmignore so that only our built files get installed. We need to run npm adduser to log in to an npm account. We can then run npm publish to publish our package and view it on npm.

Note: if you want to actually publish the package from this course, you'll need to rename it since sensitive-words is already taken. You can use a scoped package name for this as well.

magnus anderssen
magnus anderssen
~ 4 years ago

I'm sad to see the there is no discussion around the dependencies versioning. I believe the '^' is a bad practice in the npm community as it may result in broken builds in you project because of a bad "upgrade" of a dependency of dependency. It also completely destroys the possibility of obtaining the exact same build as the one in production in order to reproduce production issues locally (e.g. with instrumented for debugging code).

Trevor Miller
Trevor Millerinstructor
~ 4 years ago

Hey Magnus, I agree with you which is why I use Yarn in my personal projects with a yarn.lock. I would imagine you are already familiar with this, but if not here is an egghead lesson on it: https://egghead.io/lessons/javascript-yarn-a-javascript-package-manager

Kristof Hermans
Kristof Hermans
~ 4 years ago

Good to know is that a .npmignore file will override the .gitignore file in terms of ignoring files for NPM. So when no .npmignore is present it will use .gitignore. By creating an empty .npmignore you actually make everything visible to NPM again.

Sergey
Sergey
~ 2 years ago

Would be good to have an example on how to test what will be in end user's folder (when they install package from npm) prior to publishing to npm.