javascript - Babel : turn off import directives transpilation - Stack Overflow

I am trying to use the babel transpiler to use ES6 in a project, but i'm struggling with something

I am trying to use the babel transpiler to use ES6 in a project, but i'm struggling with something quite unusual : I'm working with an enhanced ES5 js codebase that contains imports and export directives.

Here is an example :

import Widget from 'ponent:ponent-widget';

//ES5 code here

export default "something"

I would like to keep those imports, but transpile the rest of detected ES6 features.

I did not find a way to do it so far... :/

Do you know if something like that could be possible?

Thanks in advance!

I am trying to use the babel transpiler to use ES6 in a project, but i'm struggling with something quite unusual : I'm working with an enhanced ES5 js codebase that contains imports and export directives.

Here is an example :

import Widget from 'ponent:ponent-widget';

//ES5 code here

export default "something"

I would like to keep those imports, but transpile the rest of detected ES6 features.

I did not find a way to do it so far... :/

Do you know if something like that could be possible?

Thanks in advance!

Share Improve this question asked Mar 18, 2017 at 22:10 gwenpgwenp 231 silver badge6 bronze badges 2
  • 2 Don't include module transpilation if you don't need it. Have a look at the documentation for how to configure Babel: babeljs.io/docs/plugins . – Felix Kling Commented Mar 18, 2017 at 22:18
  • Ok I got it. I was using the "env" preset, but I did not find a way to use this preset without module transpilation, so I configured my babelrc with hand picked plugins. Thank you very much! – gwenp Commented Mar 18, 2017 at 23:44
Add a ment  | 

1 Answer 1

Reset to default 8

babel-preset-env has the option modules. Setting it to false disables transformation of modules (import/export etc.).

The .babelrc would look like this:

{
  "presets": [
    ["env", { "modules": false }]
  ]
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745308428a4621854.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信