Skip to main content

@babel/plugin-proposal-import-attributes-to-assertions

提醒

此插件将生成与当前 ECMAScript 规范或任何当前提议的添加不兼容的代码。仅当你交付原生 ES 模块并且需要与不支持导入属性语法(import pkg from "./package.json" with { type: "json" })但支持旧导入断言语法(import pkg from "./package.json" assert { type: "json" })的工具兼容时才使用它,例如 Chrome 91 - 122 和 Node.js ^16.14 || ^18 || ^20 < 20.10

¥This plugin will generate code that is not compatible with the current ECMAScript specification or with any currently proposed addition to it. Only use it when you are shipping native ES modules and you need compatibility exclusively with tools that don't support the Import Attributes syntax (import pkg from "./package.json" with { type: "json" }) but support the old Import Assertions syntax (import pkg from "./package.json" assert { type: "json" }), such as Chrome 91 - 122 and Node.js ^16.14 || ^18 || ^20 < 20.10.

安装

¥Installation

npm install --save-dev @babel/plugin-proposal-import-attributes-to-assertions

用法

¥Usage

¥With a configuration file (Recommended)

babel.config.json
{
"plugins": ["@babel/plugin-proposal-import-attributes-to-assertions"]
}

通过 CLI

¥Via CLI

Shell
babel --plugins @babel/plugin-proposal-import-attributes-to-assertions script.js

通过 Node API

¥Via Node API

JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-import-attributes-to-assertions"],
});