@babel/plugin-syntax-import-attributes
備註
僅語法
此外掛僅啟用 Babel 來剖析此語法。Babel 不支援轉換此語法
此外掛啟用 Babel 來剖析 import 屬性
JavaScript
import foo from "./foo.json" with { type: "json" };
安裝
- npm
- Yarn
- pnpm
npm install --save-dev @babel/plugin-syntax-import-attributes
yarn add --dev @babel/plugin-syntax-import-attributes
pnpm add --save-dev @babel/plugin-syntax-import-attributes
用法
使用設定檔 (建議)
babel.config.json
{
"plugins": ["@babel/plugin-syntax-import-attributes"]
}
透過 CLI
Shell
babel --plugins @babel/plugin-syntax-import-attributes script.js
透過 Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-syntax-import-attributes"]
});
選項
deprecatedAssertSyntax
布林值
,預設為 false
。
如果啟用,支援使用 已過時 的 assert
關鍵字來解析匯入屬性
JavaScript
import foo from "./foo.json" assert { type: "json" };
此語法僅受 V8 為基礎的引擎支援,且正研究從 Web 中移除它。