@babel/plugin-syntax-import-attributes
注記
構文のみ
このプラグインは、Babelがこの構文を解析できるようにするだけです。Babelはこの構文の変換をサポートしていません。
このプラグインにより、Babelはインポート属性を解析できます。
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 経由
シェル
babel --plugins @babel/plugin-syntax-import-attributes script.js
Node API 経由
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-syntax-import-attributes"]
});
オプション
deprecatedAssertSyntax
boolean
、デフォルトはfalse
。
非推奨の assert
キーワードを使用してインポート属性の解析をサポートする場合は、有効にします。
JavaScript
import foo from "./foo.json" assert { type: "json" };
この構文は、V8ベースのエンジンでのみサポートされており、Webからの削除が検討されています。