[問題] 關於babel處理preset與plugin的順序問題

作者: tume209 (tume209)   2019-11-16 15:00:19
各位大大好,最近在學習babel設定時,官方說明處理順序會先使用plugin再使用preset,假設設定為下(大概示意)
presets :
[ "@babel/env" , { useBuiltInt : false } ]
plugins :
[ "@babel/plugin-transform-runtime" ]
此時要babel的代碼內有class語法,則env會生成的helper函數,而transform-runtime會接著將helper替換為引入runtime庫內的檔案。
但這樣babel處理順序不就變成
先preset → env生成helper
再plugin → 將helper移除,改成引入
這裡是不是怪怪的阿?
作者: dododavid006 (朔雪)   2019-11-18 11:58:00
雖說 plugin 跟 preset 有載入的順序問題,但是在plugin 裡也可以指定處理的時間點是要在進入一個ast node 或是離開的時候,不過最重要的其實是transform-runtime 設定了一個特殊的選項helperGenerator 改變了 babel 如何產生那些 helper所以並不是等到 helper 產生後才去做轉換,而是一開始就讓它不會被 inline 到檔案裡去
作者: tume209 (tume209)   2019-11-19 12:47:00
感謝大大說明!

Links booklink

Contact Us: admin [ a t ] ucptt.com