DEV Community

Cover image for How To Publish an NPM Package in 2020

How To Publish an NPM Package in 2020

Dorin on December 31, 2019

Introduction In essence, publishing an npm package is just one command, but there are some things that you have to take care of before d...
Collapse
 
joshuatz profile image
Joshua Tzucker

Great post! I like posts like this that get straight to the nitty-gritty of how to get things done.

Just a word of warning though, since you have both .gitignore and .npmignore as steps: these actually can conflict with each-other, and NPM will let .npmignore completely overwrite rules in .gitignore.

For example, if you ignore a password file in .gitignore, but then add a completely empty .npmignore file, the passwords will still end up in your published package (but not on Github).

Collapse
 
dorin profile image
Dorin

You're right, this could potentially lead to confusion, but I think that this is intended behaviour.
The .gitignore file is only for choosing what doesn't get commited to your git repository and .npmignore lets you specify what shouldn't get published to npm.

Collapse
 
joshuatz profile image
Joshua Tzucker

πŸ‘ Yeah, I like that description of the differences!

Collapse
 
alextremp profile image
Alex Castells

Good post πŸ‘Œ
Also for mention, it would be preferable to don't publish from a local repository, but from a CI platform instead.
For (my) open-source libs I've automatized some steps by using another open-source lib I've created for publishing via GH release tags πŸ™‚
Take a look and feel free to contribute
npmjs.com/package/versiona

Collapse
 
dorin profile image
Dorin

Great work! I'll check it out :)

Collapse
 
mbrtn profile image
Ruslan Shashkov

Too much overhead for now, unfortunately. Hope in 2021 it would be much easier.

Collapse
 
dorin profile image
Dorin

Let us know in 2021 :)

Collapse
 
mbrtn profile image
Ruslan Shashkov

With pleasure :-)

Collapse
 
portenez profile image
Victor Garcia

I wrote a pretty comprehensive post of how to automate this in gitlab ci.

vgarcia.dev/blog/2019-11-06--publi...

In case anyone's interested.

It covers typescript, testing, and using semantic release.

Collapse
 
ben profile image
Ben Halpern

I love posts like this

Collapse
 
jjjimenez100 profile image
Joshua Jimenez

Good post. Direct and concise. Thanks a lot! :)