Babel plugins run order

前端 未结 2 2063
广开言路
广开言路 2021-02-07 08:45

TL;DR: Is there a way how to specify the order in which the Babel plugins are supposed to be run? How does Babel determine this order? Is there any spec how this works apart fro

相关标签:
2条回答
  • 2021-02-07 09:11

    The order of plugins is based on the order of things in your .babelrc with plugins running before presets, and each group running later plugins/presets before earlier ones.

    The key thing though is that the ordering is per AST Node. Each plugin does not do a full traversal, Babel does a single traversal running all plugins in parallel, with each node processed one at a time running each handler for each plugin.

    0 讨论(0)
  • 2021-02-07 09:32

    Basically, what @loganfsmyth wrote is correct; there is (probably) no more magic in plugin ordering itself.

    As for the my problem specifically, my confusion was caused by how arrow function transformation works. Even if the babel-plugin-transform-es2015-arrow-functions plugin mangles the code sooner than my plugin, it does not remove the original arrow-function ast node from the ast, so even the later plugin sees it.

    Learning: when dealing with Babel, don't underestimate the amount of debug print statements needed to understand what's happening.

    0 讨论(0)
提交回复
热议问题