Table of Contents

Javascript Package - Version

About

version in a Javascript package can be found in the package.json file as property.

Syntax

Tag

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.

Version range Specification

1)

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:

Caret - increment the first non-zero portion of semver

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.

Tilde - particular version in the same minor range

To include everything greater than a particular version in the same minor range, use the tilde symbol, ~

example:

Range

Range of stable versions

specify a range of stable versions use:

examples:

Range of pre-release versions

specify a range of pre-release versions

use comparisons like > with a pre-release tag examples:

OR: Multiple sets of versions

include multiple sets of versions use || to combine examples: ^2 <2.2 || > 2.3

Resolution

If there is:

Management

Inject with WebPack

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;
}