Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create tgz file with version using npm pack?

Tags:

npm

I'm trying to create npm package (tgz) without publishing however it's not clear how to specify the version of the module.

When running npm pack it creates filename with version 0.0.0, does anyone has example to share?

like image 252
Dmitry R Avatar asked Nov 04 '15 13:11

Dmitry R


People also ask

What does npm pack do?

npm pack basically "create a tarball from a package", but here is the deal: the "package" that it creates a tarball from has to exist. So, in order to create the "package" that npm pack targets in ./dist you frequently have to run npm build .

How do I install npm version packages?

Use npm list [package-name] to know the specific latest version of an installed package. Use npm install [package-name]@[version-number] to install an older version of a package. Prefix a version number with a caret (^) or a tilde (~) to specify to install the latest minor or patch version, respectively.


2 Answers

npm pack reads the version from your package.json file. You can set the version with the npm version command:

npm version 1.2.3

If you don't yet have a package.json file, create it with npm init.

like image 91
Sam Mikes Avatar answered Sep 20 '22 19:09

Sam Mikes


above answer is valid, just adding some code and a small tip:

 { 
    "name": "my-cool-package",
    "version": "1.0.0",
    (...rest of you package.json details)
} 

npm pack command in any terminal will give you my-cool-package-1.0.0.tgz.
This will have all contents from you package.

Extra info:

In case you want to ignore any file eg node_modules add those into .npmignore in the same folder and they will be ignored.

like image 21
Clister Dmello Avatar answered Sep 21 '22 19:09

Clister Dmello