Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

javascript - Does the order of Babel 6 presets matter?

When I list the presets, does the order matter?

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

.babelrc #1

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

.babelrc #2

{
  "presets": ["react", "stage-2", "es2015"]
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.

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.

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
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...