Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add docs for plugin-proposal-import-attributes-to-assertions #2793

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions docs/plugin-proposal-import-attributes-to-assertions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
id: babel-plugin-proposal-import-attributes-to-assertions
title: "@babel/plugin-proposal-import-attributes-to-assertions"
sidebar_label: import-attributes-to-assertions
---

:::caution

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 with other 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+ and Node.js 17.2+.
nicolo-ribaudo marked this conversation as resolved.
Show resolved Hide resolved

:::

## Installation

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

## Usage

### With a configuration file (Recommended)

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

### Via CLI

```sh title="Shell"
babel --plugins @babel/plugin-proposal-import-attributes-to-assertions script.js
```

### Via Node API

```js title="JavaScript"
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-import-attributes-to-assertions"],
});
```
3 changes: 3 additions & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,8 @@ module.exports = {
"babel-plugin-proposal-throw-expressions",
"babel-plugin-proposal-unicode-sets-regex",
],
"Web Compatibility": [
"babel-plugin-proposal-import-attributes-to-assertions",
],
},
};