sibiraj-s / pkg.json-webpack-plugin

📦 Loads package.json into webpack app as an environment variable

Home Page:https://npm.im/pkg.json-webpack-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pkg.json-webpack-plugin Tests

Loads package.json into webpack app as an environment variable

Getting Started

Installation

npm i -D pkg.json-webpack-plugin
# or
yarn add --dev pkg.json-webpack-plugin

Usage

const PackageJsonPlugin = require('pkg.json-webpack-plugin');

module.exports = {
  // ...webpack config
  plugins: [new PackageJsonPlugin()],
};
console.log(process.env.pkgJson.version); // > 1.0.0

the plugin uses EnvironmentPlugin under the hood to load the values, refer the docs to know how it works

Options

the default options are

new PackageJsonPlugin({
  key: 'pkgJson',
  normalize: true,
  rootDir: process.cwd(),
  include: [],
});
  • key [string] - name of key to which package.json values are mapped to
  • normalize [boolen] - normalize and load package.json
  • rootDir [string] - directory to look for a package.json file. By default the process is expected be be run from the root direcotry where package.json exists.
  • include [array] - values only to keep from a package.json file. Empty array or any falsy values will load all values

About

📦 Loads package.json into webpack app as an environment variable

https://npm.im/pkg.json-webpack-plugin

License:MIT License


Languages

Language:JavaScript 80.7%Language:TypeScript 17.6%Language:Shell 1.8%