@babel/plugin-proposal-import-attributes-to-assertions
这个插件会生成与当前 ECMAScript 规范或任何正在提议的扩展不兼容的代码。只有在你发布原生 ES 模块,并且只需要兼容那些不支持 Import Attributes 语法(import pkg from "./package.json" with { type: "json" })但支持旧的 Import Assertions 语法(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
- Yarn
- pnpm
- Bun
npm install --save-dev @babel/plugin-proposal-import-attributes-to-assertions
yarn add --dev @babel/plugin-proposal-import-attributes-to-assertions
pnpm add --save-dev @babel/plugin-proposal-import-attributes-to-assertions
bun add --dev @babel/plugin-proposal-import-attributes-to-assertions
用法
🌐 Usage
使用配置文件(推荐)
🌐 With a configuration file (Recommended)
{
"plugins": ["@babel/plugin-proposal-import-attributes-to-assertions"]
}
通过 CLI
🌐 Via CLI
babel --plugins @babel/plugin-proposal-import-attributes-to-assertions script.js
通过 Node API
🌐 Via Node API
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-import-attributes-to-assertions"],
});