babel7-preprocessor

1.0.4 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i babel7-preprocessor

Weekly Downloads

1

Version

1.0.4

License

none

Unpacked Size

26.6 kB

Total Files

15

Last publish

Collaborators

  • zhangcheck