🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

babel-plugin-define-function

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-define-function

Babel plugin to insert templates at build time.

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

babel-plugin-define-function

A plugin for Babel 6 allows you to define dynamic variables at build time with functions.

Installation

$ npm install babel-plugin-define-function --save-dev

.babelrc

{
  "plugins": [
    ["define-function", "./path/to/config/file.js"]
  ]
}

Example

Given the following definitions:

var exec = require('child_process').execSync
var details = require('./package.json')
var buildNumber = 0

module.exports = {
	// Define a static version variable.
	__VERSION__: details.version,
	// Evaluate git commit at build time.
	__GIT_COMMIT__: function () {
		// This function will be called on each build.
			return exec('git rev-parse HEAD') + '-' + buildNumber++
	}
}

And the following file:

console.log('package version is ' + __VERSION__)
console.log('git build is ' + __GIT_COMMIT__)

becomes:

console.log('package version is ' + '1.0.0')
console.log('git build is ' + '0c25b7ea0ed7554b7da285907154b66a694c3060-0')

and on the second build (if watching):

console.log('package version is ' + '1.0.0')
console.log('git build is ' + '0c25b7ea0ed7554b7da285907154b66a694c3060-1')

Contributions

  • Use npm test to run tests.

License

MIT

Keywords

babel

FAQs

Package last updated on 28 Dec 2016

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