@babel/plugin-proposal-import-attributes-to-assertions
非官方测试版翻译
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
注意
本插件生成的代码与当前的 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。
安装
- 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
用法
通过配置文件(推荐)
babel.config.json
{
"plugins": ["@babel/plugin-proposal-import-attributes-to-assertions"]
}
通过命令行
Shell
babel --plugins @babel/plugin-proposal-import-attributes-to-assertions script.js
通过 Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-import-attributes-to-assertions"],
});