1.0.4 • Published 4 years ago

babel7-preprocessor v1.0.4

Weekly downloads
4
License
-
Repository
-
Last release
4 years ago

babel-preprocessor-next

This is a Babel plugin that adds preprocessor directives to Javascript.

Features:

  • Run code during transpilation
  • Conditional transpilation
  • Embed values calculated during transpilation into output

Installation

$ npm install babel-preprocessor

Usage

Via .babelrc

.babelrc

{
  "plugins": ["babel-preprocessor-next"]
}

Via CLI

$ babel --plugins babel-preprocessor-next script.js

Via Node API

require("@babel/core").transform("code", {
  plugins: ["babel-preprocessor-next"]
});

Syntax

IF/ELSEIF (expr, ...)

Conditional compilation.

IF (true)
    // this gets included in the output
    console.log('OK!');
ELSE
    // this does not
    console.log('NOT OK!');
END

PREP, PREPROCESS

Execute code during transpilation.

Example:
PREP
    console.log('this is executed during transpilation');
    var x = 'variables live in global context';
END