@babel/plugin-syntax-import-attributes
Syntax only
This plugin only enables Babel to parse this syntax. Babel does not support transforming this syntax
This plugin enables Babel to parse import attributes:
JavaScript
import foo from "./foo.json" with { type: "json" };
Installation
- npm
- Yarn
- pnpm
npm install --save-dev @babel/plugin-syntax-import-attributes
yarn add --dev @babel/plugin-syntax-import-attributes
pnpm add --save-dev @babel/plugin-syntax-import-attributes
Usage
With a configuration file (Recommended)
babel.config.json
{
"plugins": ["@babel/plugin-syntax-import-attributes"]
}
Via CLI
Shell
babel --plugins @babel/plugin-syntax-import-attributes script.js
Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-syntax-import-attributes"]
});
Options
deprecatedAssertSyntax
boolean
, defaults to false
.
If enabled, support parsing import attributes using the deprecated assert
keyword:
JavaScript
import foo from "./foo.json" assert { type: "json" };
This syntax is only supported in V8-based engines, and its removal from the web is being investigated.