简体   繁体   English

使用babel-register“only”选项

[英]Using the babel-register `only` option

I have the following config in my .babelrc: 我的.babelrc中有以下配置:

{
    "presets": ["react", "es2015"],
    "only": ["app/**/*.js", "src/**/*.js", "test/**/*.js", "node_modules/my-module/**/*.js"]
}

I basically want my-module in the node_modules directory to be passed through babel, and so am using the only option. 我基本上希望node_modules目录中的my-module通过babel传递,所以我使用only选项。

However, it doesn't seem to be working. 但是,它似乎没有起作用。 Any ES6 I write—whether in my-module or even just app/app.js—isn't transpiled, and so breaks my app. 我编写的任何ES6 - 无论是在我的模块中,还是只是app / app.js - 都没有被编译,因此破坏了我的应用程序。

Any ideas? 有任何想法吗? Am I misunderstanding the documentation? 我误解了文档吗?

Previously I was doing the following: 以前我做的如下:

require('babel-register')({
    ignore: function (filename) {
        if (filename.indexOf('node_modules') === -1) {
            return false;
        }

        return filename.indexOf('@lostmyname/styleguide') === -1;
    }
});

However, I need to use the .babelrc because I'm adding mocha, which only supports the require hook with no options. 但是,我需要使用.babelrc,因为我正在添加mocha,它只支持require hook而没有选项。

Apparently this was caused by a bug in babel: https://github.com/babel/babel/issues/3789 显然这是由一个巴贝尔的错误引起的: https//github.com/babel/babel/issues/3789

It's been fixed: https://github.com/babel/babel/pull/3644 它已被修复: https//github.com/babel/babel/pull/3644

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM