Reputation: 2375
I want to write a babel plugin, and there is a transfromFileSync call in my plugin. I need to get the options of transformFileSync. How to do it?
// run transformFile
var babel = require('babel-core');
var path = require('path');
var options = {
plugins: [path.resolve('./plugin.js')],
presets: ['es2015']
};
babel.transformFile('./test.js', options);
// plugin.js
module.exports = function (babel) {
return {
Program: function () {
// how to get babel options here
}
}
}
Upvotes: 2
Views: 602
Reputation: 21
You can't get the babel options. But you can get your plugin options in the second param of visitor like:
export default function({ types: t }) {
return {
visitor: {
FunctionDeclaration(path, state) {
console.log(state.opts);
}
}
}
}
Upvotes: 1