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

flavors.macro

v0.4.0

Published

Macro for building different flavors of a react-app

Readme

Flavors.macro

npm version Babel Macro

Macro for building different flavors of an app by manipulating import headers. Built and tested in apps made with create-react-app.

Description

flavors.macro is a babel-plugin-macros, which will build different flavors of a react-application.

Installation

# NPM
$ npm install --save-dev flavors.macro

# Yarn
$ yarn add flavors.macro

Usage

Flavors

A placholder for a flavor, called a flavor-key, needs to be configured. This key can be used in the import statements in the app. Against this key, flavors can be added.

Add the following into the .babel-plugin-macrosrc.json at the root of the project.

{
    "babelMacros": {
        "flavorsConfig": {
            "flavorsMap": {
                "layout-theme": "green",
            }
        }
    }
}

Here the the flavors-key is layout-theme. The current flavor being green.

If, for some reason, you cannot include the .babel-plugin-macrosrc.json file to your project, you can use any of the methods mentioned here.

You can then use the flavor-key in any class by adding the macro-key as the last element, in the name of the import string or just before the extension. You can use flavors in the directory-level as well. Just make sure to call the flavor() function, after all the import statements.

In the below example, the flavor-key layout-theme, configured above, is being used -

// Import flavors on top
import flavors from 'flavors.macro'

import Hello from './hello.layout-theme.js'
import Bye from './bye.layout-theme'
import Constants from './constants.layout-theme/theme'
import Config from './layout-theme.config/config'
import Theme from './layout-theme/theme'
// ... other imports

// Add this right after all the imports are declared (won't work otherwise)
flavors();

When the application is built, the above statements will evaluate to -

import Hello from './hello.green.js'
import Bye from './bye.green'
import Constants from './constants.green/theme'
import Config from './green.config/config'
import Theme from './green/theme'
// ... other imports

NOTE: After adding/editing the configuration file(.babel-plugin-macrosrc.json or if any of the other equivalents being used), the npm server needs to be manually restarted.

Multiple flavor-keys can be added to the flavorsMap. If there are no flavor-keys, then a default key defaultFlavor is assumed, which will be replaced by an empty string.

getFlavor

If the difference between flavors is really small/subtle or if there is already existing code, in which the flavors need to be created for a small portion of it, creating separate files for all of the different flavors can be cumbersome.

The getFlavor() macro call-expression can be used to fetch the flavor for the corresponding flavor-key.

So for the configuration from the above examples -

import { getFlavor } from 'flavors.macro'

// ... Rest of the code
var currFlavor = getFlavor("layout-theme")
switch (currFlavor) {
    case "green":
        console.log("Using green flavor")
        break;
    case "red":
        console.log("Using red flavor")
        break;
    case "":
    default:
        console.log("No such flavor found")
}

getFlavor will return an empty string if the flavor-key is incorrect.

Building and running locally

  • All the source-code is inside the src directory.
  • Ideally any change that's made needs to have a test. Running the tests - npm test.
  • Whenever testing out in the example-app, make sure to run npm run-script build in the project-root, since it'll be picking up from the local-env. NOTE: lib dir is git-ignored, so you'll not be able to see any-change tracked by git.
  • Deploy to npm using - npm publish

License

MIT. See license file