I might be wrong but i couldn't find any solution to give some custom options to my custom babel plugin. Do you have any clue how i could achieve this ?
Here is my building process, i'm using gulp with browserify and babelify :
gulp.task("scripts", function() {
return browserify({
entries: "myFile.js"
})
.transform(babelify.configure({
plugins: ["./lib/myPlugin:after"]
}))
.bundle()
.pipe(source("all.js"))
.pipe("build/");
});
I would like to give some custom data to my plugin, doing something like this :
gulp.task("scripts", function() {
return browserify({
entries: "myFile.js"
})
.transform(babelify.configure({
myCustomOptions: {
rootPath: "some path",
customInfo: "..."
}
plugins: ["./lib/myPlugin:after"]
}))
.bundle()
.pipe(source("all.js"))
.pipe("build/");
});
Then in my plugin, i would like to retrieve the customOptions object i just declared. Would there be a way to achieve something like that ?
Thanks,
Regards
Using a Preset Within a Babel config, if the preset is on npm, you can pass in the name of the preset and Babel will check that it's installed in node_modules already. This is added to the presets config option, which takes an array. Otherwise, you can also specify a relative or absolute path to your presets.
Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.
Ordering matters for each visitor in the plugin. This means if two transforms both visit the "Program" node, the transforms will run in either plugin or preset order. Plugins run before Presets. Plugin ordering is first to last.
This has changed recently in Babel 6. From the docs:
Plugins can specify options. You can do so in your config by wrapping it in an array and providing a options object. For example:
{ "plugins": [ ["transform-async-to-module-method", { "module": "bluebird", "method": "coroutine" }] ] }
Plugin Options documentation in the Babel plugin handbook.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With