babel-engine-plugin icon indicating copy to clipboard operation
babel-engine-plugin copied to clipboard

`babel-engine-plugin` does not use `.babelrc`

Open thasmo opened this issue 8 years ago • 2 comments

It seems babel-engine-plugin currently uses it's own babel-core version, which prevents proper use of the project's .babelrc file, in my case.

.babelrc looks like this:

{
    "presets": [
        ["@babel/preset-env", {
            "useBuiltIns": "usage",
            "loose": true,
            "modules": false
        }],
        "@babel/preset-stage-3"
    ]
}

When adding the plugin by calling new BabelEnginePlugin() it seems that the settings in the .babelrc file are ignored - not sure why, but I guess as it's using an older babel-core version, it's not working.

When adding the plugin by calling new BabelEnginePlugin({presets: ['env']}) it works "properly", but it's not using the configured presets in .babelrc either.

I'm wondering how this would work properly. Is there a way to get it to use the .babelrc settings?

thasmo avatar Feb 16 '18 10:02 thasmo

To be honest, I'm not really a Babel guru at all. I mainly created this plugin because we got very many requests from users to transpile libraries to ES5. So I don't think I would be able to help you out with the problem unfortunately. If you find a solution, I would be happy to receive a PR so I can merge it in.

SamVerschueren avatar Feb 16 '18 10:02 SamVerschueren

Here's a hacky workaround...

const babelrc = JSON.parse(fs.readFileSync('.babelrc', 'utf8'))
new BabelEnginePlugin(babelrc)

I'm actually getting an error about Unexpected token operator <<*>> but that's probably because one of my deps uses a generator and I exclude that in my .babelrc.

timwis avatar Apr 09 '18 11:04 timwis