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 🙏

© 2026 – Pkg Stats / Ryan Hefner

parcel-transformer-vars

v1.0.1

Published

![](https://img.shields.io/npm/dm/parcel-transformer-vars.svg)![](https://img.shields.io/npm/v/parcel-transformer-vars.svg)![](https://img.shields.io/npm/l/parcel-transformer-vars.svg)

Readme

parcel-transformer-vars

A Parcel 2.0+ plugin for injecting variables based on a JS config.

Why I made this:

I want to be able to easily inject variable values into my JS that are dynamic to the environment and easily grab things like version numbers from the package.json without having my app require it directly and potentially including more than I want.

I want these variables to be able to exist anywhere in my JS and I want them to be injected as the right type of value based on the type that the value is in my config.

For example if you define the following vars object;

const pkg = require('./package.json')

module.exports = {
  APP_VERSION: pkg.version,
  BUILD_TIME: Date.now(),
  IS_AWESOME: true,
}

Examples:

// will also replace quotes so it will evaluate to 'number'
// after being replaced.
console.log(typeof 'BUILD_TIME')
// This will stay a string because the value is a string
console.log(typeof 'APP_VERSION')
// This will become a boolean (removing quotes)
console.log(typeof 'IS_AWESOME')

How to use it

Create a .varsrc.js config at the root of your directory. It should contain something like this:

const pkg = require('./package.json')

module.exports = {
  // grab version from package.json
  APP_VERSION: pkg.version,
  // grab app name from package.json
  APP_NAME: pkg.name,
  // some other thing
  API_URL: process.env.API_URL || 'https://dev.api.com',
  // this one will be a boolean that will be `false` when you run `parcel build`
  IS_DEV: process.env.NODE_ENV !== 'production',
}

Then, you must tell parcel to use the plugin. So you create / edit your .parcelrc as follows:

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.js": ["parcel-transformer-vars", "..."]
  }
}

Note: the "..." is important it tells parcel to do this first before the other stuff it would normally do.

If with that .varsrc.js and .parcelrc when you use Parcel in dev server or build mode this plugin will inject variables.

So, this:

if ('IS_DEV') {
  console.log('This whole block will be totally gone when running parcel build')
}

Please note: this also works in inline JS you have in your HTML.

tests

See packages/parcel-test-project

install

npm install parcel-transformer-vars

Change log

  • 1.0.1: Adding check in case plugin config is not defined yet
  • 1.0.0: First public release.

credits

If you like this follow @HenrikJoreteg on twitter.

license

MIT