支援的瀏覽器
從 v1.1.10
開始,您現在可以使用 browserslist
自動設定支援的瀏覽器。
用法
.swcrc
{
"env": {
"targets": {
"chrome": "79"
},
"mode": "entry",
"coreJs": "3.22"
}
}
選項
目標
字串 | 陣列<字串> | { [字串]: 字串 }
,預設為 {}
。
描述專案支援/鎖定的環境。這可以是 與 browserslist 相容(在新分頁中開啟) 查詢 (有其限制)(在新分頁中開啟)
.swcrc
{
"env": {
"targets": "> 0.25%, not dead"
}
}
或支援的最低環境版本物件
.swcrc
{
"env": {
"targets": {
"chrome": "58",
"ie": "11"
}
}
}
環境範例
chrome
opera
edge
firefox
safari
ie
ios
android
node
electron
如果未指定 targets
,SWC 將使用 browserslist
取得目標資訊。
path
字串
,預設為目前目錄。路徑
指定要載入browserslist
模組和任何 browserslist 組態檔的目錄。例如,.browserslistrc
或 package.json 中的browserslist
欄位。如果您的建置系統不在專案根目錄中,這會很有用。
mode
字串
,預設為undefined
。- 可能的值:
usage
、entry
、undefined
(這會比對 Babel 中的useBuiltIns
(在新分頁中開啟))
⚠️
usage
模式目前不如 Babel 有效率,如果您有類似 "foo"["a" + "t"]()
的用法。SWC 沒有評估表達式 "a" + "t"
,也不會包含 String.prototype.at
polyfill。
skip
定義要略過的 ES 功能以減少套件大小。例如,您的 .swcrc
可能是
.swcrc
{
"env": {
"skip": ["core-js/modules/foo"]
}
}
coreJs
字串
,預設為undefined
。coreJs
指定要使用的core-js
版本,可以是 swc 支援的任何 core-js 版本。例如,"3.22"
。
此選項與 mode: "usage"
或 mode: "entry"
搭配使用時會生效。建議指定次要版本(例如,"3.22"
),否則 "3"
會被解釋為 "3.0"
,這可能不包含最新功能的 polyfill。
其他選項
debug
: (布林值) 預設為false
。dynamicImport
: (布林值) 預設為false
。loose
: (布林值) 預設為false
。針對允許的任何外掛套件啟用 寬鬆轉換。include
: (字串陣列) 可以是core-js
模組 (es.math.sign
) 或 SWC 通行證 (transform-spread
)。exclude
: (字串陣列) 可以是core-js
模組 (es.math.sign
) 或 SWC 通行證 (transform-spread
)。shippedProposals
: (布林值) 預設為false
。forceAllTransforms
: (布林值) 預設為false
。啟用所有可能的轉換。