babel7-preprocessor
v1.0.4
Published
This is a Babel plugin that adds preprocessor directives to Javascript.
Downloads
1
Readme
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