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?
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 .
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.
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With