Javascript Package - Version

1 - About

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

3 - Syntax

3.1 - 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.

3.2 - Caret

By default, npm adds your package using the caret operator in front of the version number (for example, ^3.5.2). We recommend using the tilde operator instead (for example, ~3.5.2), which limits updates to the most recent patch-level version.

4 - Resolution

If there is:

  • no package.json file in the root directory, the latest version of the package is installed.
  • package.json file, the latest version satisfying the semver rule declared in package.json for that package (if there is any) is installed.

5 - Management

5.1 - Inject with WebPack

Read the version from Javascript Package - Package.json and inject it with the DefinePlugin in Webpack.

Example:

  • Import the name

const webpack = require('webpack');
var packageJson = require('./package.json');

  • Use the DefinePlugin and set the version in process.env.VERSION

var config = {
    ....
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
            'process.env.VERSION': JSON.stringify(packageJson.version)
        })
    ],
    ....
};

  • In the code, the text process.env.VERSION will be replaced at compile time with the version.

export default myLib = {
    version: process.env.VERSION;
}


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap