What is @babel/plugin-syntax-import-meta?
The @babel/plugin-syntax-import-meta npm package allows Babel to parse the import.meta syntax, which is a meta-property exposing context-specific metadata to a JavaScript module. This plugin only allows Babel to parse this syntax; it doesn't implement any transformation.
What are @babel/plugin-syntax-import-meta's main functionalities?
Parsing import.meta syntax
This feature enables Babel to understand and parse the import.meta syntax, which is typically used to get information about the module itself, like its URL.
console.log(import.meta); // { url: 'file:///path/to/current/module.js' }
Other packages similar to @babel/plugin-syntax-import-meta
@babel/plugin-transform-modules-commonjs
This package transforms ECMAScript modules to CommonJS, allowing for the use of import and export syntax in environments that do not natively support it. It doesn't specifically provide functionality for import.meta, but it is related to module transformation.
babel-plugin-transform-es2015-modules-amd
Similar to the CommonJS plugin, this transforms ES2015 modules to Asynchronous Module Definition (AMD) format. While it deals with module syntax, it does not handle import.meta.
@babel/plugin-syntax-import-meta
Allow parsing of import.meta
See our website @babel/plugin-syntax-import-meta for more information.
Install
Using npm:
npm install --save-dev @babel/plugin-syntax-import-meta
or using yarn:
yarn add @babel/plugin-syntax-import-meta --dev