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.
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).
Hey Magnus, I agree with you which is why I use Yarn in my personal projects with a
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.
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.