tolosa / babel-plugin-demo

Custom babel plugin example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Babel plugin demo

Example about how to write and configure a simple custom babel plugin

Adds a new JS identifier called answerToTheUltimateQuestionOfLifeTheUniverseAndEverything, that it will be replaced with the value 42 by Babel in compile time.

For example, it should convert this code:

console.log(`What is the answer?: ${answerToTheUltimateQuestionOfLifeTheUniverseAndEverything}`);

...to this one:

console.log(`What is the answer?: ${42}`);

Setup

Run npm install.

Usage

Run the compiler:

npm run build

It will compile the source file in sample/index.js to lib/index.js. Check the code of both files to see the difference. The compiled file can be executed with node lib.

About

Custom babel plugin example


Languages

Language:JavaScript 100.0%