What is @babel/plugin-proposal-export-namespace-from?
The @babel/plugin-proposal-export-namespace-from package allows developers to use the export * as syntax in their JavaScript or TypeScript code, which is part of the ECMAScript 2020 (ES2020) specification. This syntax enables a module to re-export all exports of another module, creating a single named export that encapsulates all of them.
What are @babel/plugin-proposal-export-namespace-from's main functionalities?
Re-exporting all named exports from a module
This feature allows a module to re-export all named exports from another module under a single namespace. In the code sample, all exports from './utils' are available as properties of the 'utils' object.
export * as utils from './utils';
Other packages similar to @babel/plugin-proposal-export-namespace-from
@babel/plugin-syntax-export-namespace-from
This package allows Babel to parse the export * as syntax but does not transform it. It is useful when you want to enable the syntax but are using a bundler or environment that already supports it natively.
babel-plugin-transform-export-extensions
This package is a Babel plugin that adds support for the export-from extension syntax, which includes export * as. It is similar to @babel/plugin-proposal-export-namespace-from but is not scoped under the official Babel namespace and may not be as up-to-date with Babel's plugin API.
@babel/plugin-proposal-export-namespace-from
Compile export-ns-from statements to ES2015
Example
export * as ns from 'mod';
Installation
npm install --save-dev @babel/plugin-proposal-export-namespace-from
Usage
Via .babelrc
(Recommended)
.babelrc
{
"plugins": ["@babel/plugin-proposal-export-namespace-from"]
}
Via CLI
babel --plugins @babel/plugin-proposal-export-namespace-from script.js
Via Node API
require("@babel/core").transform("code", {
plugins: ["@babel/plugin-proposal-export-namespace-from"]
});
References