This is a Babel plugin that adds preprocessor directives to Javascript.
- Run code during transpilation
- Conditional transpilation
- Embed values calculated during transpilation into output
$ npm install babel-preprocessor
.babelrc
{
"plugins": ["babel-preprocessor-next"]
}
$ babel --plugins babel-preprocessor-next script.js
require("@babel/core").transform("code", {
plugins: ["babel-preprocessor-next"]
});
Conditional compilation.
IF (true)
// this gets included in the output
console.log('OK!');
ELSE
// this does not
console.log('NOT OK!');
END
Execute code during transpilation.
PREP
console.log('this is executed during transpilation');
var x = 'variables live in global context';
END