メインコンテンツにスキップ

@babel/plugin-syntax-import-attributes

注記

構文のみ

このプラグインは、Babelがこの構文を解析できるようにするだけです。Babelはこの構文の変換をサポートしていません。

このプラグインにより、Babelはインポート属性を解析できます。

JavaScript
import foo from "./foo.json" with { type: "json" };

インストール

npm install --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からの削除が検討されています。