Babel 6预设的顺序是否重要?

时间:2021-08-31 14:44:40

When I list the presets, does the order matter?

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

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

换句话说,以下.babelrc文件是等效的吗?

.babelrc #1

.babelrc#1

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

.babelrc #2

.babelrc#2

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

1 个解决方案

#1


33  

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

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

Plugin/Preset Ordering

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.

订购插件中每个访问者的事项。这意味着如果两个变换都访问“Program”,则变换将以插件或预设顺序运行。

Plugins run before Presets.

Plugin ordering is first to last.

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

Preset ordering is reversed (last to first).

Yes this is confusing, see babel/notes #2.

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

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.

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

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

#1


33  

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

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

Plugin/Preset Ordering

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.

订购插件中每个访问者的事项。这意味着如果两个变换都访问“Program”,则变换将以插件或预设顺序运行。

Plugins run before Presets.

Plugin ordering is first to last.

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

Preset ordering is reversed (last to first).

Yes this is confusing, see babel/notes #2.

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

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.

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

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