2.1.0 • Published 4 years ago

babel-plugin-pkg v2.1.0

Weekly downloads
12
License
-
Repository
github
Last release
4 years ago

babel-plugin-pkg



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

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

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


(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

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)