version in a Javascript package can be found in the package.json file as property.
Tags are a supplement to semver (e.g., v0.12) for organizing and labeling different versions of packages. In addition to being more human-readable, tags allow publishers to distribute their packages more effectively.
This specification permits to upgrade the package by the package manager.
For example, to specify acceptable version ranges up to 1.0.4, use the following syntax:
To include everything that does not increment the first non-zero portion of semver, use the caret (aka hat) symbol, ^
Example:
By default, npm adds your package using the caret operator in front of the version number (for example, ^3.5.2). It's recommend using the tilde operator instead (for example, ~3.5.2), which limits updates to the most recent patch-level version.
To include everything greater than a particular version in the same minor range, use the tilde symbol, ~
example:
specify a range of stable versions use:
examples:
specify a range of pre-release versions
use comparisons like > with a pre-release tag examples:
include multiple sets of versions use || to combine examples: ^2 <2.2 || > 2.3
If there is:
Read the version from Javascript Package - Package.json and inject it with the DefinePlugin in Webpack.
Example:
const webpack = require('webpack');
var packageJson = require('./package.json');
var config = {
....
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.VERSION': JSON.stringify(packageJson.version)
})
],
....
};
export default myLib = {
version: process.env.VERSION;
}