有没有办法为babel插件提供自定义选项?

Sam*_*uve 4 javascript plugins babeljs

我可能错了,但我找不到任何解决方案,为我的自定义babel插件提供一些自定义选项.你有什么线索我能做到这一点吗?

这是我的构建过程,我正在使用浏览器和babelify gulp:

gulp.task("scripts", function() {
    return browserify({
        entries: "myFile.js"
    })
    .transform(babelify.configure({
        plugins: ["./lib/myPlugin:after"]
    }))
    .bundle()
    .pipe(source("all.js"))
    .pipe("build/");
});
Run Code Online (Sandbox Code Playgroud)

我想给我的插件提供一些自定义数据,做这样的事情:

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/");
});
Run Code Online (Sandbox Code Playgroud)

然后在我的插件中,我想检索刚刚声明的customOptions对象.有没有办法实现这样的目标?

谢谢,

问候

mik*_*1aj 6

最近在Babel 6中发生了变化.来自文档:

插件可以指定选项.您可以通过将其包装在数组中并提供选项对​​象来在配置中执行此操作.例如:

{
  "plugins": [
    ["transform-async-to-module-method", {
      "module": "bluebird",
      "method": "coroutine"
    }]
  ]
}
Run Code Online (Sandbox Code Playgroud)

Babel插件手册中的插件选项文档.