Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sibiraj-s/pkg.json-webpack-plugin
📦 Loads package.json into webpack app as an environment variable
https://github.com/sibiraj-s/pkg.json-webpack-plugin
package-json webpack webpack-plugin
Last synced: about 1 month ago
JSON representation
📦 Loads package.json into webpack app as an environment variable
- Host: GitHub
- URL: https://github.com/sibiraj-s/pkg.json-webpack-plugin
- Owner: sibiraj-s
- License: mit
- Created: 2019-12-27T21:23:13.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-24T09:45:19.000Z (5 months ago)
- Last Synced: 2024-12-22T23:33:56.686Z (2 months ago)
- Topics: package-json, webpack, webpack-plugin
- Language: TypeScript
- Homepage: https://npm.im/pkg.json-webpack-plugin
- Size: 1.82 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# pkg.json-webpack-plugin [](https://github.com/sibiraj-s/pkg.json-webpack-plugin/actions)
> Loads package.json into webpack app as an environment variable
## Getting Started
### Installation
```bash
npm i -D pkg.json-webpack-plugin
# or
yarn add --dev pkg.json-webpack-plugin
```### Usage
```js
const PackageJsonPlugin = require('pkg.json-webpack-plugin');module.exports = {
// ...webpack config
plugins: [new PackageJsonPlugin()],
};
``````js
console.log(process.env.pkgJson.version); // > 1.0.0
```the plugin uses [EnvironmentPlugin](https://webpack.js.org/plugins/environment-plugin/) under the hood to load the values, refer the docs to know how it works
## Options
the default options are
```js
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](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) 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](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) values will load all values