npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@oliver-schoendorn/babel-plugin-transform-define

v2.0.0

Published

This babel plugin will take a set of config values (or load them from a file path) and replace all occurrences in the parsed scripts.

Downloads

3

Readme

babel-plugin-transform-define

Build Status Coverage Status

This Babel plugin will take a set of config values (or load them from a file path) and replace all occurrences in the parsed scripts. This plugin is compatible with Babel 7. Other Babel versions have not been tested.

npm i -D @oliver-schoendorn/babel-plugin-transform-define

Configuration example (.babelrc, static config)

{
    "plugins": [
        [ "@oliver-schoendorn/babel-plugin-transform-define", {
            "values": { "your": "values" } 
        } ]
    ]
}

Configuration example (.babelrc, config from file)

{
    "plugins": [
        [ "@oliver-schoendorn/babel-plugin-transform-define", {
            "file": "./src/config" 
        } ]
    ]
}

Examples

All of the following example will use these plugin config values:

{
  "values": {
    "process.env.NODE_ENV": "production",
    "isProduction": true,
    "CONFIG": {
      "API_HOST": "https://your.domain/"
    },
    "VAR": null,
    "TEST_STUFF": "/^foo$/igm",
    "didRTFM": true
  }
}

Variable declarations

Input

const initState = { initialized: true }
const appState = { global: { ...CONFIG, isProduction }, ...initialized }
const thisWorks = asWell = isProduction
const VAR = { CONFIG }

Output

const initState = { initialized: true }
const appState = { global: { ...{ "API_HOST": "https://your.domain" } }, ...initialized }
const thisWorks = asWell = true
const VAR = { CONFIG: { "API_HOST": "https://your.domain" } }

Assignments and calls

Input

const myObject = {}, isProduction = false
myObject.foo = VAR
myObject.isProduction = isProduction

new RegExp(TEST_STUFF)

Object.keys(CONFIG).map(key => console.log(key))

Output

const myObject = {}, isProduction = false
myObject.foo = null
myObject.isProduction = isProduction

new RegExp("/^foo$/igm")

Object.keys({ "API_HOST": "https://your.domain" }).map(key => console.log(key))

Exports

Input

export { CONFIG }
export default isProduction

Output

const CONFIG = { "API_HOST": "https://your.domain" }
export { CONFIG }

const isProduction = true
export default isProduction

Conditionals evaluation

Input

if (isProduction) { doThings() }
else { doSomthingElse() }

if (! isProduction) { whatEver() }
else { sorcery() }

const youAre = didRTFM ? 'awesome' : 'lazy'
const complicated = didRTFM && ! isProduction

const canNotEvaluate = didRTFM && require('./aScript')

Output

{ doThings() }
{ sorcery() }

const youAre = 'awesome'
const complicated = false
const canNotEvaluate = true && require('./aScript')

Options

| Option key | Description | Type | Default value | |---------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|----------------| | values | Object with keys and values, that should be replaced. Please note that only the top level keys will be used for replacement. If you want to define process.env.NODE_ENV for instance, use { "process.env.NODE_ENV": "production" } | object | {} | | file | Instead of passing an object, you can also reference a file. The given path has to be relative to your babel config and should use module.exports = { API_HOST: "https://..." } | string | undefined | | memberExpressions | You can disable the processing of member expressions (node.env.NODE_ENV). | boolean | true | | exportExpressions | Toggles the processing of export expressions (export { MY_CONFIG } or export default MY_CONFIG). Note: If you enable this option, you will have to set the babel parser option allowUndeclaredExports to true. | boolean | true | | evaluateConditionals | Toggles the evaluation and simplification of If Statements, Unary Statements and so on. | boolean | true | | verbose | If set to true, some information about the replaced nodes and their types will be printed to the console. | boolean | false |