0.0.3 • Published 5 months ago

jser.macro v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

jser.macro

Here is a collection of some babel macros I created.

Usage

  1. install babel-plugin-macros and add it to your babel config.
  2. choose one macro from list below and start shipping.

Marco List

1. runCodeForEnvVar() - run code for specific env var and strip the code if not found.

import { runCodeForEnvVar } from "jser.macro";

runCodeForEnvVar("ENABLE_DEBUG", () => {
  console.log("ENABLE_DEBUG enabled! 1");
});
runCodeForEnvVar("ENABLE_ADVANCED_LOGGING", () => {
  console.log("ENABLE_ADVANCED_LOGGING enabled! 2");
});
runCodeForEnvVar("ENABLE_AB_TEST", () => {
  console.log("ENABLE_AB_TEST enabled");
});

Let's say if ENABLE_DEBUG=true ENABLE_ADVANCED_LOGGING=true is set when build, then the built asset will be like sth below. See that the last call expression is stripped completely.

(() => {
  console.log("ENABLE_DEBUG enabled! 1");
})();
(() => {
  console.log("ENABLE_ADVANCED_LOGGING enabled! 2");
})();
0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago