FormidableLabs/babel-plugin-transform-define

Name: babel-plugin-transform-define

Owner: Formidable

Description: Compile time code replacement for babel similar to Webpack's DefinePlugin

Created: 2016-03-19 23:18:20.0

Updated: 2018-01-13 09:23:51.0

Pushed: 2017-11-27 15:54:41.0

Homepage:

Size: 38

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

babel-plugin-transform-define

npm version

Compile time code replacement for babel similar to Webpack's DefinePlugin


Quick Start
install babel-plugin-transform-define

.babelrc


lugins": [
["transform-define", {
  "process.env.NODE_ENV": "production",
  "typeof window": "object"
}]


.babelrc


lugins": [
["transform-define", "./path/to/config/file.js"]


Note: Paths are relative to process.cwd()`

Reference Documentation

babel-plugin-transform-define can transform certain types of code as a babel transformation.

Identifiers

.babelrc


lugins": [
["transform-define", {
  "VERSION": "1.0.0",
}]


Source Code

ION;

ow.__MY_COMPANY__ = {
rsion: VERSION

Output Code

.0";

ow.__MY_COMPANY__ = {
rsion: "1.0.0"


Member Expressions

.babelrc


lugins": [
["transform-define", {
  "process.env.NODE_ENV": "production"
}]


Source Code

process.env.NODE_ENV === "production") {
nsole.log(true);

Output Code

true) {
nsole.log(true);


Unary Expressions

.babelrc


lugins": [
["transform-define", {
  "typeof window": "object"
}]


Source Code

of window;
of window === "object";

Output Code

ect';
;

License

MIT License


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.