Babel 6预设的顺序是否重要? [英] Does the order of Babel 6 presets matter?

查看:169
本文介绍了Babel 6预设的顺序是否重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我列出预设时,订单是否重要?

When I list the presets, does the order matter?

换句话说,是以下 .babelrc 等价文件?

In other words, are the following .babelrc files equivalent?

.babelrc #1

{
  "presets": ["es2015", "stage-2", "react"]
}

.babelrc #2

{
  "presets": ["react", "stage-2", "es2015"]
}


推荐答案

来自 babeljs.io/docs/plugins:(截至2016年9月30日)

From babeljs.io/docs/plugins: (as of 9/30/2016)

对插件中的每个访问者进行排序。这意味着如果两个变换都访问Program,则变换将以插件或预设顺序运行。

Ordering matters for each visitor in the plugin. This means if two transforms both visit "Program", the transforms will run in either plugin or preset order.

"plugins": [
  "transform-decorators-legacy", // will run first
  "transform-class-properties" // will run second
]



预设顺序相反(从最后到第一个)。



是的这令人困惑,请参阅 babel / notes#2

我认为(对于向后兼容性)的原因是大多数用户首先列出es2015和0秒。而且-0阶段将在2015年之前运行。

I believe the reason why (for backwards compatability) is that most users had listed "es2015" first and "stage-0" second. And stage-0 would run before es2015.

"presets": [
  "es2015", // will run third
  "react", // will run second
  "stage-2" // will run first
]

这篇关于Babel 6预设的顺序是否重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆