Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-pkg

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-pkg

Resolves _PKG_VERSION to version from package.json - also works with any other field!

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-pkg

License Sponsor babel-plugin-pkg
Build status Commits since v2.1.0 Last commit Issues
Latest version on npm Dependents Downloads

Resolves _PKG_VERSION to version from package.json - also works with any other field!

This plugin attempts to dynamically replace expressions starting with process.env.REPLACE_PKG_.

Installation

babel-plugin-pkg on npm

npm install --save-dev babel-plugin-pkg@^2.1.0

babel-plugin-pkg on Yarn

yarn add --dev babel-plugin-pkg@^2.1.0

@jaid/babel-plugin-pkg on GitHub Packages
(if configured properly)

npm install --save-dev @jaid/babel-plugin-pkg@^2.1.0

Example

Reference fields from your package.json in your source files.

package.json

{
  "name": "readable-ms",
  "version": "1.2.3"
}

src/index.js

console.log(`This is ${process.env.REPLACE_PKG_NAME} v${process.env.REPLACE_PKG_VERSION}`)

This will be transpiled to: dist/index.js

console.log("This is readable-ms v1.2.3")

Usage

Add to your Babel configuration.

.babelrc.js

module.exports = {
  plugins: [
    "pkg"
  ]
}

Options

DefaultInfo
cwd(determined by Babel)The directory which the search for the package.json file begins in.
nameFallbacktrueIf true and package.json does not contain a "name" field, the folder name that contains the chosen package.json file will be used as replacement.
prefixREPLACE_PKG_Only members of process.env starting with this string will be replaced.

Development

Setting up:

git clone git@github.com:jaid/babel-plugin-pkg.git
cd babel-plugin-pkg
npm install

Testing:

npm run test:dev

Testing in production environment:

npm run test

License

MIT License
Copyright © 2020, Jaid <jaid.jsx@gmail.com> (https://github.com/jaid)

Keywords

FAQs

Package last updated on 04 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc